This is WebConfig code I am working on:
package hello.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/greeting").setViewName("greeting");
}
}
And this is my Application.class
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
It seems to be a spring-boot issue that these class methods don't get called in some systems. The corresponding issue is reported at: https://github.com/spring-projects/spring-boot/issues/2870
My question is, can we map resources mapped in this class, outside this class as a temporary workaround?
If yes, how do we do this?
Update: Following Andy Wilkinson's suggestion I removed @EnableWebMvc
and the demo app started working. Then I tried stripping down project files one by one to see at what point error disappears. I found that I had two classes in the project, one, extended from WebMvcConfigurationSupport
and the second, from WebMvcConfigurerAdapter
. removing the former class from the project fixed the error.
What I want to know is, why did this happen? Secondly, why doesnt this error appear on all systems?