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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to