编程语言
首页 > 编程语言> > java.lang.ClassNotFoundException:org.springframework.core.ResolvableTypeProvider

java.lang.ClassNotFoundException:org.springframework.core.ResolvableTypeProvider

作者:互联网

参见英文答案 > What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?                                    15个
我编写了一个Spring注释的调度程序,但是当我执行它时会在帖子标题中给出错误消息.

SchedulerConfig.java

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import com.fwd.pmap.scheduler.SchedulerApp;

@Configuration
@EnableScheduling
public class SchedulerConfig implements SchedulingConfigurer {

    @Bean
    public SchedulerApp bean() {
        return new SchedulerApp();
    }

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    @Bean(destroyMethod="shutdown")
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(4);
    }
}

SchedulerApp.java

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fwd.pmap.memberInterfaceFile.CsvReader;
import com.fwd.pmap.memberInterfaceFile.CsvWriter;;

@Component
public class SchedulerApp
{
    @Scheduled(cron="0 0 17 * ? *")
    public void importInterfaceFile()
    {
        CsvReader reader = new CsvReader();
        try {
            reader.importInterfaceFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Scheduled(cron="0 0 6 * ? *")
    public void generateInterfaceFile()
    {
        CsvWriter writer = new CsvWriter();
        try {
            writer.generateInterfaceFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

以及启动调度程序作业的主类

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;

public class SchedulerMain
{
    @SuppressWarnings({ "unused", "resource" })
    public static void main(String[] args) {
        AbstractApplicationContext context = new AnnotationConfigApplicationContext(SchedulerConfig.class);
    }
}

我得到的错误信息是:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/ResolvableTypeProvider
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.fwd.pmap.scheduler.SchedulerMain.main(SchedulerMain.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.ResolvableTypeProvider
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more

的pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fwd</groupId>
  <artifactId>fwd-PMAP</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <jboss.version>3.0.2.Final-redhat-15</jboss.version>
    <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
    <maven-war-plugin.version>2.6</maven-war-plugin.version>

    <!-- Spring -->
    <spring-framework.version>4.0.3.RELEASE</spring-framework.version>

    <!-- Hibernate / JPA -->
    <hibernate.version>4.2.21.Final</hibernate.version>

    <!-- Logging -->
    <logback.version>1.1.7</logback.version>

    <!-- Restlet -->
    <restlet.version>2.3.4</restlet.version>
    <commons-lang.version>3.4</commons-lang.version>
    <jackson.version>2.7.1</jackson.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.jboss.spec</groupId>
      <artifactId>jboss-javaee-6.0</artifactId>
      <version>${jboss.version}</version>
      <type>pom</type>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
          <groupId>org.jboss.spec.javax.ws.rs</groupId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- Spring ORM support -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring-framework.version}</version>
    </dependency>

    <!-- Spring Scheduler -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>1.3.3.RELEASE</version>
    </dependency>

    <!-- Logging -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
    </dependency>

    <!-- Hibernate -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernate.version}</version>
    </dependency>

    <!-- Super CSV -->
    <dependency>
      <groupId>net.sf.supercsv</groupId>
      <artifactId>super-csv</artifactId>
      <version>2.4.0</version>
    </dependency>

    <!-- Excel Writer -->
    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>3.9</version>
    </dependency>

    <!-- Copy POJO to POJO -->
    <dependency>
      <groupId>org.modelmapper</groupId>
      <artifactId>modelmapper</artifactId>
      <version>0.7.5</version>
    </dependency>

    <!-- Restlet -->
    <dependency>
      <groupId>org.restlet.jee</groupId>
      <artifactId>org.restlet.ext.servlet</artifactId>
      <version>${restlet.version}</version>
    </dependency>

    <dependency>
      <groupId>org.restlet.jse</groupId>
      <artifactId>org.restlet.ext.json</artifactId>
      <version>${restlet.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>${commons-lang.version}</version>
    </dependency>

    <!-- JSON -->
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.0.4</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>

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

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <version>${maven-war-plugin.version}</version>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${maven-compiler-plugin.version}</version>
          <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

它曾经在2个月前工作正常,直到我最近重新访问代码并发现它被破坏了.任何人都可以给指针?

解决方法:

cd进入项目目录.

使用:

mvn dependency:tree

查看你的lib jar是否存在冲突版本.

标签:java,spring,maven,spring-scheduled
来源: https://codeday.me/bug/20190702/1353786.html