xxl-job 启动spring boot工程xxl.job.core.executor.XxlJobExecutor抛空指针

ergxz8rk  于 2021-11-29  发布在  Java
关注(0)|答案(3)|浏览(1330)

Please answer some questions before submitting your issue. Thanks!

Which version of XXL-JOB do you using?

xxl-job 2.2.0
springboot 2.3.4.RELEASE

Expected behavior

正常启动spring boot工程

Actual behavior

启动抛出空指针

Steps to reproduce the behavior

Other information

pom.xml

<?xmlversion="1.0"encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.Jin10</groupId>
    <artifactId>schedule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>schedule</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--        配置Mysql依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
        </dependency>

        <!--        配置lombok依赖-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!--        配置Mybatis-plus依赖-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.0</version>
        </dependency>

        <!-- xxl-job-core -->
        <dependency>
            <groupId>com.xuxueli</groupId>
            <artifactId>xxl-job-core</artifactId>
            <version>2.2.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
  1. appcation配置文件
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/spider-manage?useSSL=false&useUnicode=true&characterEncoding=utf-8
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      #logic-delete-field: flag  # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
      logic-delete-value: 1 # 逻辑已删除值(默认为 1)
      logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)

xxl:
  job:
    admin:
      addresses: http://localhost:8088/xxl-job-admin 
    executor:
      appname: local-executor 
      ip: 
      port: 10001
      logpath:  
      logretentiondays: 30 
    accessToken: jin10
server:
  port: 18888
  1. xxlconfig
@Configuration
public class XxlJobConfig {
    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;
    @Value("${xxl.job.executor.appname}")
    private String appName;
    @Value("${xxl.job.executor.ip}")
    private String ip;
    @Value("${xxl.job.executor.port}")
    private int port;
    @Value("${xxl.job.accessToken}")
    private String accessToken;
    @Value("${xxl.job.executor.logpath}")
    private String logPath;
    @Value("${xxl.job.executor.logretentiondays}")
    private int logRetentionDays;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        // 创建 XxlJobSpringExecutor 执行器
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        // 返回
        return xxlJobSpringExecutor;
    }
}
  1. 执行器执行逻辑类
@Component
public class DemoJobHandler extends IJobHandler {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @XxlJob(value = "Job")
    @Override
    public ReturnT<String> execute(String param) throws Exception {

        return ReturnT.SUCCESS;

    }
}
  1. 启动抛出的异常信息
.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2021-01-04 11:28:18.875  INFO 10884 --- [           main] com.jin10.schedule.ScheduleApplication   : Starting ScheduleApplication on DESKTOP-PEVRKGP with PID 10884 (E:\Ryan\schedule\target\classes started by 13121 in E:\Ryan\schedule)
2021-01-04 11:28:18.877  INFO 10884 --- [           main] com.jin10.schedule.ScheduleApplication   : No active profile set, falling back to default profiles: default
2021-01-04 11:28:19.281  WARN 10884 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.jin10.schedule.mapper]' package. Please check your configuration.
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Property 'mapperLocations' was not specified.
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.4.0 
2021-01-04 11:28:19.883  INFO 10884 --- [           main] c.xxl.job.core.executor.XxlJobExecutor   : >>>>>>>>>>> xxl-job register jobhandler success, name:Job, jobHandler:com.xxl.job.core.handler.impl.MethodJobHandler@1e34c607[class com.jin10.schedule.service.DemoJobHandler#execute]
2021-01-04 11:28:19.890  INFO 10884 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-04 11:28:19.916  INFO 10884 --- [           main] com.jin10.schedule.ScheduleApplication   : Started ScheduleApplication in 1.308 seconds (JVM running for 1.866)
2021-01-04 11:28:19.919  INFO 10884 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2021-01-04 11:28:19.922 ERROR 10884 --- [extShutdownHook] c.xxl.job.core.executor.XxlJobExecutor   : null

java.lang.NullPointerException: null
	at com.xxl.job.core.thread.ExecutorRegistryThread.toStop(ExecutorRegistryThread.java:117) ~[xxl-job-core-2.2.0.jar:na]
	at com.xxl.job.core.server.EmbedServer.stopRegistry(EmbedServer.java:262) ~[xxl-job-core-2.2.0.jar:na]
	at com.xxl.job.core.server.EmbedServer.stop(EmbedServer.java:124) ~[xxl-job-core-2.2.0.jar:na]
	at com.xxl.job.core.executor.XxlJobExecutor.stopEmbedServer(XxlJobExecutor.java:158) [xxl-job-core-2.2.0.jar:na]
	at com.xxl.job.core.executor.XxlJobExecutor.destroy(XxlJobExecutor.java:85) [xxl-job-core-2.2.0.jar:na]
	at com.xxl.job.core.executor.impl.XxlJobSpringExecutor.destroy(XxlJobSpringExecutor.java:55) [xxl-job-core-2.2.0.jar:na]
	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:258) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1092) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1085) [spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1061) [spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1030) [spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:949) [spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]

2021-01-04 11:28:19.922  INFO 10884 --- [FileCleanThread] c.x.j.core.thread.JobLogFileCleanThread  : >>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.
2021-01-04 11:28:19.923  INFO 10884 --- [rCallbackThread] c.x.j.core.thread.TriggerCallbackThread  : >>>>>>>>>>> xxl-job, executor callback thread destory.
2021-01-04 11:28:19.923  INFO 10884 --- [       Thread-6] c.x.j.core.thread.TriggerCallbackThread  : >>>>>>>>>>> xxl-job, executor retry callback thread destory.

Process finished with exit code 0
ekqde3dh

ekqde3dh1#

环境一样,我也遇到一样的问题,网上的方法试了,也是不行。

eqqqjvef

eqqqjvef2#

XxlJobConfig 类里面 appName 改成 appname试试 在最新的源码中已经是appname了

sg2wtvxw

sg2wtvxw3#

我也报一样的异常,后来发现我项目里在定义Feign调用接口时,参数未加@RequestParm ,虽然可以省略,但是.XxlJobExecutor会报 Method has too many Body parameters 异常,版本更换为2.1.1后解决

相关问题