3 回答
TA贡献1155条经验 获得超0个赞
添加@ActiveProfiles("test")到您的测试类
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { App.class }, webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration
@TestPropertySource("classpath:/application-test.properties")
@ActiveProfiles("test")
public class CheckingServiceTest {
TA贡献1815条经验 获得超12个赞
尝试将您的 TestPropertySource 注释更改为:
@TestPropertySource(locations = "classpath:application-test.properties")
TA贡献1851条经验 获得超4个赞
从项目中删除 XML 配置并尝试创建每个 bean 注释驱动。
使用@Value 为每个变量赋值或使用创建单独的类
@Configuration
public class TestConfiguration {
@Bean(name = "publishJNDITemplate")
public JndiTemplate publishJNDITemplate() {
final Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, factoryIntial);
environment.put(Context.PROVIDER_URL, providerUrl);
environment.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
environment.put(Context.SECURITY_CREDENTIALS, securityCredentials);
environment.put(narfeedTopics, destination);
return new JndiTemplate(environment);
}
}
添加回答
举报