You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/06/30 03:46:31 UTC
[GitHub] [shardingsphere-elasticjob] xdxTao opened a new issue #1917: I don't understand how to configure one-time scheduling in springboot
xdxTao opened a new issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917
**MyJob**
```java
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Component;
@Component
public class MyElasticJob implements SimpleJob {
@Override
public void execute(ShardingContext context) {
System.out.println("--------------------");
System.out.println(context.getShardingTotalCount() + " " + context.getShardingItem());
System.out.println("--------------------");
}
}
```
<br/>
**MyYML**
```yml
elasticjob:
regCenter:
serverLists: 127.0.0.1:2181
namespace: my-job2
jobs:
simpleJob:
elasticJobClass: com.elastic.job.MyElasticJob
cron: 0/1 * * * * ?
shardingTotalCount: 2
jobBootstrapBeanName: myElasticJob
```
<br/>
**MyController**
```java
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class OneOffJobController {
// 通过 "@Resource" 注入
@Resource(name = "myElasticJob")
private OneOffJobBootstrap myOneOffJob;
@GetMapping("/execute")
public String executeOneOffJob() {
myOneOffJob.execute();
return "{\"msg\":\"OK\"}";
}
// 通过 "@Autowired" 注入
@Autowired
@Qualifier("myElasticJob")
private OneOffJobBootstrap myOneOffJob2;
@GetMapping("/execute2")
public String executeOneOffJob2() {
myOneOffJob2.execute();
return "{\"msg\":\"OK\"}";
}
}
```
<br/>
**StratError**
```
Could not register object [org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap@5e1fc2aa] under bean name 'myElasticJob': there is already object [com.elastic.job.MyElasticJob@688d411b] bound
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] TeslaCN commented on issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917#issuecomment-871514447
Hi @xdxTao
Just rename the class `MyElasticJob` or rename the value of jobBootstrapBeanName.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] xdxTao commented on issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
xdxTao commented on issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917#issuecomment-871867374
> Hi @xdxTao
> Just rename the class `MyElasticJob` or rename the value of jobBootstrapBeanName.
Hi @TeslaCN
I changed the class to `onejob` and the `jobBootstrapBeanName` according to you, but still can't。
**job**
```java
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Component;
@Component
public class OneJob implements SimpleJob {
@Override
public void execute(ShardingContext context) {
System.out.println(context.getShardingTotalCount() + " " + context.getShardingItem());
}
}
```
**yml**
```yml
elasticjob:
regCenter:
serverLists: 127.0.0.1:2181
namespace: my-job8
jobs:
myElasticJob:
elasticJobClass: com.elastic.job.OneJob
cron: 0/10 * * * * ?
shardingTotalCount: 1
jobBootstrapBeanName: myOonBean
```
**controller**
```java
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class OneOffJobController {
// 通过 "@Resource" 注入
@Resource(name = "myOonBean")
private OneOffJobBootstrap myOneOdasdasffJob;
@GetMapping("/execute")
public String executeOneOffJob() {
myOneOdasdasffJob.execute();
return "{\"msg\":\"OK\"}";
}
}
```
**pom**
```xml
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>elasticJob</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-lite-spring-boot-starter</artifactId>
<version>3.0.0-RC1</version>
</dependency>
</dependencies>
```
**startError**
```
Bean named 'myOonBean' is expected to be of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap' but was actually of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap'
```
The error is that the bean type is wrong. Is there any configuration missing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] xdxTao removed a comment on issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
xdxTao removed a comment on issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917#issuecomment-871157559
I changed the bean name:myElasticJobBean
startError:
```
Bean named 'myElasticJobBean' is expected to be of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap' but was actually of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] xdxTao commented on issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
xdxTao commented on issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917#issuecomment-871156990
I changed the bean name:myElasticJobBean
startError:
```
Bean named 'myElasticJobBean' is expected to be of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap' but was actually of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] TeslaCN closed issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
TeslaCN closed issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere-elasticjob] xdxTao commented on issue #1917: I don't understand how to configure one-time scheduling in springboot
Posted by GitBox <gi...@apache.org>.
xdxTao commented on issue #1917:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1917#issuecomment-871157559
I changed the bean name:myElasticJobBean
startError:
```
Bean named 'myElasticJobBean' is expected to be of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.OneOffJobBootstrap' but was actually of type 'org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org