Controller not called by Tomcat when application is deployed like war
I am working on a web application using SpringBoot.
The problem I am facing is as follows. The app works fine with Eclipse, but when I deploy the project as war in tomcat 7 it gives me "HTTP Status 404". No exception was found in tomcat logs.
Below is my controller:
@RestController
public class TinyUrlController{
@Autowired TinyUrlService tinyUrlService;
@RequestMapping("/create")
public String createUrl(@RequestParam("url") String url,HttpServletRequest request){
TinyUrl tinyUrl = tinyUrlService.createUrl(url);
return tinyUrl.toString();
}
}
source to share
Your app doesn't seem to have an entry point, why you don't have anything. Just create an entry point to your application.
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<Application> applicationClass = Application.class;
}
See also Spring Boot Deployment Guide
source to share
I suggest you try to build a mock app using http://start.spring.io/
It will make a SpringBoot application It will also make java packages Just remember to place your controllers under the java package "demo" .. otherwise they cannot be "automatically connected" without additional configuration ...
I suggest you create a simple controller that just returns "hello" as a starter ...
source to share