Spring Boot中的库不匹配问题

时间:2018-05-07 16:34:01

标签: java spring-boot cucumber

我的Spring-boot应用程序运行良好,直到我开始摆弄弹簧靴和黄瓜测试。不能确切地说出了什么问题但是从我的研究来看,我pom.xml

中的库依赖性不匹配
<?xml version="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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>EmploymentBootCamp</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>EmploymentBootCamp</name>
<description>Demo project for Spring Boot Employment Boot Camp</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <start-class>EmploymentBootCamp.demo.EmploymentBootCampApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.auth0</groupId>
        <artifactId>java-jwt</artifactId>
        <version>3.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.4</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.4</version>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>1.2.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-test</artifactId>
        <version>2.0.1.RELEASE</version>
        <scope>test</scope>
        <type>jar</type>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.1.RELEASE</version>
            <configuration>
                <mainClass>EmploymentBootCamp.demo.EmploymentBootCampApplication</mainClass>
                <layout>ZIP</layout>
            </configuration>
        </plugin>
    </plugins>
</build>

我得到的错误低于

  

java.lang.NoClassDefFoundError:org / springframework / dao / support / PersistenceExceptionTranslator       at java.lang.ClassLoader.defineClass1(Native Method)〜[na:1.8.0_152]       在java.lang.ClassLoader.defineClass(ClassLoader.java:763)〜[na:1.8.0_152]       在java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)〜[na:1.8.0_152]       在java.net.URLClassLoader.defineClass(URLClassLoader.java:467)〜[na:1.8.0_152]       在java.net.URLClassLoader.access $ 100(URLClassLoader.java:73)〜[na:1.8.0_152]       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:368)〜[na:1.8.0_152]       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:362)〜[na:1.8.0_152]       at java.security.AccessController.doPrivileged(Native Method)〜[na:1.8.0_152]       at java.net.URLClassLoader.findClass(URLClassLoader.java:361)〜[na:1.8.0_152]       在java.lang.ClassLoader.loadClass(ClassLoader.java:424)〜[na:1.8.0_152]       在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338)〜[na:1.8.0_152]       在java.lang.ClassLoader.loadClass(ClassLoader.java:357)〜[na:1.8.0_152]       在org.springframework.data.jpa.util.BeanDefinitionUtils。(BeanDefinitionUtils.java:55)〜[spring-data-jpa-2.0.6.RELEASE.jar:2.0.6.RELEASE]       在org.springframework.data.jpa.repository.support.EntityManagerBeanDefinitionRegistrarPostProcessor.postProcessBeanFactory(EntityManagerBeanDefinitionRegistrarPostProcessor.java:54)〜[spring-data-jpa-2.0.6.RELEASE.jar:2.0.6.RELEASE]       在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)〜[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]       在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:179)〜[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)〜[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)〜[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]       在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]       在EmploymentBootCamp.demo.EmploymentBootCampApplication.main(EmploymentBootCampApplication.java:10)[classes /:na]   引起:java.lang.ClassNotFoundException:org.springframework.dao.support.PersistenceExceptionTranslator       在java.net.URLClassLoader.findClass(URLClassLoader.java:381)〜[na:1.8.0_152]       在java.lang.ClassLoader.loadClass(ClassLoader.java:424)〜[na:1.8.0_152]       在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:338)〜[na:1.8.0_152]       在java.lang.ClassLoader.loadClass(ClassLoader.java:357)〜[na:1.8.0_152]       ...省略了25个常见帧

1 个答案:

答案 0 :(得分:1)

您可以安全地删除此依赖项:

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

通过 spring-boot-starter-data-jpa 您已经具有对 spring-tx 的传递依赖性。

通过将 spring-tx 显式绑定到测试范围,将其从编译范围(mavens默认范围)中删除< / p>