Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到java.lang.NoClassDefFoundError类:javax/servlet/SessionCookieConfig_Java_Spring_Spring Mvc_Spring Boot_Integration Testing - Fatal编程技术网

找不到java.lang.NoClassDefFoundError类:javax/servlet/SessionCookieConfig

找不到java.lang.NoClassDefFoundError类:javax/servlet/SessionCookieConfig,java,spring,spring-mvc,spring-boot,integration-testing,Java,Spring,Spring Mvc,Spring Boot,Integration Testing,我在项目中有依赖项 compile("org.springframework.boot:spring-boot-starter-data-jpa") { exclude group: "org.apache.tomcat", module: "tomcat-jdbc" exclude group: "org.hibernate", module: "hibernate-entitymanager" } compile("org.springframework.boot:spri

我在项目中有依赖项

 compile("org.springframework.boot:spring-boot-starter-data-jpa") {
    exclude group: "org.apache.tomcat", module: "tomcat-jdbc"
    exclude group: "org.hibernate", module: "hibernate-entitymanager"
}
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-mail")
compile("org.springframework.boot:spring-boot-configuration-processor")
compile("org.eclipse.persistence:org.eclipse.persistence.jpa")
compile("org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen.processor")
compile("com.google.api-client:google-api-client")
compile("com.google.oauth-client:google-oauth-client-jetty")
compile("com.google.apis:google-api-services-drive")

   // dependencies from the inherited module (compile(project("..."))
    api("com.fasterxml.jackson.core:jackson-databind")
    api("org.hibernate.validator:hibernate-validator")
    api("commons-validator:commons-validator")
    api("org.apache.commons:commons-lang3")
    implementation("com.google.guava:guava")
我想做集成测试,所以我添加了依赖项

testCompile("com.github.springtestdbunit:spring-test-dbunit:1.3.0")
testCompile("org.dbunit:dbunit:2.5.4")
我创建了基本配置类

/**
 * Spring configuration class for integration tests.
 */
@Configuration 
@EnableAutoConfiguration 
@ComponentScan
public class PopcornCoreTestApplication {}
和一个抽象类

/**
 * Base class to save on configuration.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = PopcornCoreTestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@TestExecutionListeners(
        {
                DependencyInjectionTestExecutionListener.class,
                DirtiesContextTestExecutionListener.class,
                TransactionalTestExecutionListener.class,
                TransactionDbUnitTestExecutionListener.class
        }
)
public abstract class DBUnitTestBase {

    @Autowired
    private UserRepository userRepository;

    /**
     * Clean out the db after every test.
     */
    @After
    public void cleanup() {
        this.userRepository.deleteAll();
    }
}
和一些示例测试来检查它是否有效

/**
 * Integration tests for UserPersistenceServiceImpl.
 */
public class UserPersistenceServiceImplIntegrationTests extends DBUnitTestBase {

    @Autowired
    private UserPersistenceService userPersistenceService;

    /**
     * Setup.
     */
   @Test
    public void setup() {
        Assert.assertThat(this.userRepository.count(), Matchers.is(0L));
    }
}
而且它不起作用。我要开始考试了

    lip 04, 2018 6:30:10 PM org.springframework.boot.test.context.SpringBootTestContextBootstrapper buildDefaultMergedContextConfiguration
INFO: Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.jonki.popcorn.core.jpa.service.UserPersistenceServiceImplIntegrationTests], using SpringBootContextLoader
lip 04, 2018 6:30:10 PM org.springframework.test.context.support.AbstractContextLoader generateDefaultLocations
INFO: Could not detect default resource locations for test class [com.jonki.popcorn.core.jpa.service.UserPersistenceServiceImplIntegrationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
lip 04, 2018 6:30:11 PM org.springframework.boot.test.context.SpringBootTestContextBootstrapper getTestExecutionListeners
INFO: Using TestExecutionListeners: [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@769e7ee8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@5276e6b0, org.springframework.test.context.transaction.TransactionalTestExecutionListener@71b1176b, com.github.springtestdbunit.TransactionDbUnitTestExecutionListener@6193932a]

java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
...

lip 04, 2018 6:30:12 PM org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@769e7ee8] to prepare test instance [com.jonki.popcorn.core.jpa.service.UserPersistenceServiceImplIntegrationTests@402bba4f]
java.lang.NoClassDefFoundError: javax/servlet/SessionCookieConfig
关于所有错误

我试图添加一个依赖项

javax.servlet-api
但这没有帮助,同样的错误仍然存在


如何处理这个问题?

SessionCookieConfig类出现在3.0版的servlet api中

要解决问题,只需将此依赖项添加到build.gradle文件中即可

testCompile("javax.servlet:javax.servlet-api:3.1.0")

对于所有mvn用户,请在pom.xml中添加以下依赖项

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>test</scope>
</dependency>

javax.servlet
javax.servlet-api
3.1.0
测试