Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

WebMvcTest not ignoring custom redis configuration

$
0
0

The main class is like so:

@SpringBootApplication@EnableCaching@ComponentScan({"com.sample", "com.sample.lib"})public class Application extends SpringBootServletInitializer {    /**     * The main method.     *     * @param args the arguments     */    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }    /**     * Configure.     *     * @param builder the builder     * @return the spring application builder     */    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(Application.class);    }}

The custom config

@Configurationpublic class RedissonSpringDataConfig {    @Bean    public RedissonConnectionFactory redissonConnectionFactory(RedissonClient redisson) {        return new RedissonConnectionFactory(redisson);    }   .....

Test class:

@RunWith(SpringRunner.class)@WebMvcTest(controllers = ConfigController.class ,excludeAutoConfiguration = { RedissonConfiguration.class,        RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class, RedissonSpringDataConfig.class })@AutoConfigureMockMvc//@TestPropertySource(properties="spring.data.redis.repositories.enabled=false")class ConfigControllerTest {    @Autowired    private MockMvc mockMvc;    @MockBean    private RestTemplate restTemplate;

This throws

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'redisson' threw exception; nested exception is java.net.UnknownHostException: failed to resolve 'redis' after 4 queries

I tried a bunch of options with TestPropertySource annotation. I read a couple of answers that ComponentScan would be the source of this error but couldn't fix with a couple of what I thought would be workarounds. Can someone help to ignore the custom redis client config class?

I commented out the @Configuration on custom configuration class but this would not be a graceful workaround.


Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>