vineet kala
vineet kala

Reputation: 41

Controller not invoked by Tomcat when application is deployed as war

I am working on a web application using SpringBoot.

The problem I am facing is as follows. The application is running fine from Eclipse, but when I deploy the project as a war in tomcat 7, it's giving me "HTTP Status 404". No exception 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();

    }
}

Upvotes: 3

Views: 2432

Answers (2)

anders
anders

Reputation: 195

I suggest that you try to build your application layout by using http://start.spring.io/

It will make a SpringBoot application It will make java packages right too Just remember to place your controllers under java package "demo".. otherwise they cannot be "auto wired" without more configuration...

I suggest you make a simple controller that just returns "hello" as a starter...

Upvotes: 0

njjnex
njjnex

Reputation: 1555

Seems your application have no entry point that's why you got nothing. Just create entry point into 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 deploying guide

Upvotes: 2

Related Questions