I have the following spring test configuration with different profiles:
@Configuration
@ComponentScan (value = {"uk.co.test.ws" })
public class SpringTestConfig
{
@Profile( "local")
@PropertySource( "classpath:/config/local/settings.properties" )
public static class SpringTestConfigLocal
{
@Autowired
private Environment environment ;
@Bean(name= "baseUrl" )
public String setBaseUrl()
{
return environment .getRequiredProperty("baseurl.protocol" )+"://" +environment .getRequiredProperty( "baseurl.host");
}
}
and then created a base class that takes in the base url
> @RunWith (SpringJUnit4ClassRunner. class) @ContextConfiguration
> (classes = { SpringTestConfig. class }) public class BaseWsTest {
> @Autowired
> String baseUrl;
which then gets extended to other test classes like below:
public class SampleFTest extends BaseWsTest
{
@Test
public void hello() throws FileNotFoundException, Exception
{
System. out .println("base url: " + baseUrl );
When run using normal maven clean install the tests works but if I was to run it by right-clicking the method it gets a
Error creating bean with name 'uk.co.test.ws.service.base.SampleFTest': Injection of autowired dependencies failed;
Aucun commentaire:
Enregistrer un commentaire