2017-09-17 13 views
1

私は、com.app.config' and a controller located at com.app.controller​​com.app.controller`にある、Springブート@Configurationクラスを持っています。私がそれを実行すると、設定クラスは決して使用されません。@ConfigurationクラスがSpringブートテストで実行されないのはなぜですか?

package com.app.config; 

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.validation.Validator; 
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 


@Configuration 
@EnableWebMvc 
@ComponentScan("com.app") 
public class ValidationConfig { 

    @Bean 
    public Validator validator() { 

     //The breakpoint here is never called! 
     return new LocalValidatorFactoryBean(); 
    } 
} 

Testクラス:

import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.test.context.junit4.SpringRunner; 
import org.springframework.validation.Validator; 

@RunWith(SpringRunner.class) 
@ComponentScan({"com.app","com.app.config"}) 
public class TestAumController { 

    //...elided... 

    @Autowired 
    private Validator validator; 

    @Test 
    public void testController() throws Exception { 
     //..edlided... 
    } 
} 

答えて

2

@ComponentScan@Configurationクラスのためです。テストクラスのそれを@SpringBootTestに置き換えてください。アプリケーションコンテキストをロードして設定します。

関連する問題