2
私はspring-boot-starter-parent 1.4.3.RELEASEを使用していて、mockito-all 2.0.2-betaを使ってテストケースを書きました。私の春を@MockBean使用した後...二回なぜスプリングブートアプリケーションが2回起動するのですか
2017-02-08 12:03:11.135 INFO 9375 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$61cd4862] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ))))
' |____| .__|_| |_|_| |_\__, |////
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.3.RELEASE)
2017-02-08 12:03:11.268 INFO 9375 --- [ main] c.v.d.chain.PublisherChainResourceTest : No active profile set, falling back to default profiles: default
2017-02-08 12:03:11.271 INFO 9375 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.Generi[email protected]: startup date [Wed Feb 08 12:03:11 IST 2017]; parent: org.spring[email protected]4adfb1f
........................
2017-02-08 12:03:24.109 INFO 9375 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$61cd4862] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ))))
' |____| .__|_| |_|_| |_\__, |////
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.3.RELEASE)
2017-02-08 12:03:24.267 INFO 9375 --- [ main] c.v.d.t.AdNetworkParamResourceTest : No active profile set, falling back to default profiles: default
2017-02-08 12:03:24.272 INFO 9375 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.s[email protected]7fcc9949: startup date [Wed Feb 08 12:03:24 IST 2017]; parent: org.spring[email protected]17660e9a
私のアプリケーションを開始しました.yml、
spring:
datasource:
url: jdbc:hsqldb:mem:testdb;sql.syntax_mys=true
username:
password:
driver-class-name: org.hsqldb.jdbcDriver
testOnBorrow: true
validationQuery: SELECT 1
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
show_sql: true
endpoints:
health:
sensitive: false
server:
tomcat:
basedir: target/tomcat
accesslog:
enabled: true
pattern: "%v %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %S %D"
liquibase:
user:
password:
default-schema: your_schema
enabled: false
解決方法 私は次のように
私のテストを「クリーンMVNがインストール」を実行したときに春が二回起動するのはなぜ..
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigMyApplication.class)
@WebAppConfiguration
public class XXResourceTest extends AbstractTransactionalJUnit4SpringContextTests {
private static final String PATH = "/xxxxxxx/";
@Autowired
XXXXXRepository xxxxxRepository;
@MockBean
@Autowired
XXXXXApiService xxxxxApiService;
@Autowired
WebApplicationContext webApplicationContext;
MockMvc mockMvc;
HttpHeaders headers;
int xxxId = 1;
int parentId = 1;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
MockitoAnnotations.initMocks(this);
headers = new HttpHeaders();
headers.add(CONTENT_TYPE, APPLICATION_JSON);
}
@Test
public void createXXXTest() throws JsonProcessingException, Exception {
DtoInput input = new DtoInput();
input.setXXXId(xxxId);
input.setParentId(parentId);
Parent parent = new Parent();
parent.setId(parentId);
when(xxxxxApiService.getParent(parentId)).thenReturn(parent);
mockMvc.perform(post(PATH).content(new ObjectMapper().writeValueAsString(input)).headers(headers))
.andDo(print()).andExpect(status().isCreated())
.andExpect(jsonPath("$.xxId", is(xxId)))
.andExpect(jsonPath("$.type", is("type")))
.andExpect(jsonPath("$.parentId", is(parentId)));
}
テストクラスを表示します。 – notionquest
@SSTあなたのConfigMyApplication.classはSpringBootApplicationとしてアノテートされていますか?代わりにTestConfigurationアノテーションを使用してみてください – rvit34