2016-09-14 52 views
5

Tôi có ứng dụng khởi động mùa xuân rất đơn giản 1.4 với một bộ điều khiển còn lại. Khi tôi đã cố gắng để kiểm tra tải bối cảnh này tôi đang nhận được lỗi như dưới đây: -Lỗi thử nghiệm khởi động mùa xuân 1.4 ứng dụng

13:29:03.623 [main] DEBUG o.s.t.c.j.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.628 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 
13:29:03.632 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 
13:29:03.641 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 
13:29:03.644 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.650 [main] DEBUG o.s.b.t.c.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests]: using defaults. 
13:29:03.659 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.AutoConfigureReportTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] 
13:29:03.667 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute] 
13:29:03.671 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource] 
13:29:03.672 [main] INFO o.s.b.t.c.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]2db7a79b, org.springframework.test[email protected]6950e31, org.springframework.b[email protected]b7dd107, org.springframewor[email protected]42eca56e, org.springfra[email protected]52f759d7, org.springframework.boot.test.autoconfi[email protected]7cbd213e, org.spri[email protected]192d3247, org.springf[email protected]3ecd23d9, org.springframework[email protected]569cfc36] 
13:29:03.674 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.674 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.690 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.690 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.691 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.691 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.692 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.692 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.695 [main] DEBUG o.s.t.c.s.AbstractDirtiesContextTestExecutionListener - Before test class: context [[email protected] testClass = FrontendServiceApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = FrontendServiceApplicationTests, locations = '{}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'null', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null]. 
13:29:03.696 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.696 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.byteobject.cloudsanthe.frontendservice.FrontendServiceApplicationTests] 
13:29:03.697 [main] DEBUG o.s.t.c.s.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[[email protected] testClass = FrontendServiceApplicationTests, testInstance = com.byteobj[email protected]548ad73b, testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = FrontendServiceApplicationTests, locations = '{}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'null', parent = [null]]]]. 
13:29:03.699 [main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.b[email protected]b7dd107] to prepare test instance [com.byteobj[email protected]548ad73b] 
java.lang.IllegalStateException: Failed to load ApplicationContext 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) 
    at org.springframework.boot.test.autoconfigure.AutoConfigureReportTestExecutionListener.prepareTestInstance(AutoConfigureReportTestExecutionListener.java:49) 
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 
Caused by: java.lang.IllegalArgumentException: Cannot load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration or @ContextHierarchy. 
    at org.springframework.util.Assert.notNull(Assert.java:115) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:91) 
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) 
    ... 24 common frames omitted 
13:29:03.705 [main] DEBUG o.s.t.c.s.AbstractDirtiesContextTestExecutionListener - After test class: context [[email protected] testClass = FrontendServiceApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = FrontendServiceApplicationTests, locations = '{}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'null', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null]. 

lớp thử nghiệm là: -

@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) 
public class FrontendServiceApplicationTests { 

@Test 
public void contextLoads() { 
} 

} 

Và lớp ứng dụng là: -

@SpringBootApplication 
@ImportResource({"classpath:dbContext.xml",  "classpath:dbClientMappingContext.xml"}) 
public class FrontendServiceApplication { 

/** 
* The main method. 
* 
* @param args the arguments 
*/ 
public static void main(String[] args) { 
    SpringApplication.run(FrontendServiceApplication.class, args); 
} 
} 

Những gì tôi đang làm sai ở đây?

+1

'Cân nhắc chú thích lớp thử nghiệm của bạn với @ContextConfiguration hoặc @ContextHierarchy. tại org.springframework.util.Assert.notNull (Assert.java:115) ' – Jens

Trả lời

5

Có vẻ như Spring Boot không thể tìm thấy lớp học @SpringBootApplication của bạn bằng cách sử dụng quét đường dẫn lớp.

Vì vậy, cung cấp cho các sau một thử:

@RunWith(SpringRunner.class) 
@SpringBootTest(
    classes = FrontendServiceApplication.class, 
    webEnvironment = WebEnvironment.RANDOM_PORT 
) 
public class FrontendServiceApplicationTests { 

    @Test 
    public void contextLoads() { 
    } 

} 
+0

Cảm ơn Sam, có vấn đề có liên quan đến classpath, gradle đã messedup cài đặt của tôi. –

Các vấn đề liên quan