I wrote a small project using SpringBoot with several RESTful services to learn the framework and REST technology. When run through spring-boot: run, everything works correctly, is available at http: // localhost: 8080 / and then follow the links specified via @RequestMapping in the controller. For example, by http: // localhost: 8080 / restapp / test / {id}:

@RequestMapping(value = "http ://localhost:8080/restapps-0.0.1-SNAPSHOT/restapp/test/{id}", method = RequestMethod.GET) public String getWelcome(@PathVariable(value = "id") String id) { return "Welcome to jax-rs " + id; } 

When trying to deploy to full tomcat, the project runs on http: // localhost: 8080 / project_version and opens the default index.html file (which I learned by chance, because this file was transferred for initial testing), and then to services there is no access to all addresses:

http: // localhost: 8080 / project_version / restapp / test / {id}

http: // localhost: 8080 / project_version / test / {id}

http: // localhost: 8080 / project_version / project_name / restapp / test / {id}

gives 404.

Application.java

 @Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); } } 

Controller.java

 @RestController public class Controller extends ApplicationConfig { @Override public Set<Class<?>> getClasses() { Set<Class<?>> s = new HashSet<Class<?>>(); s.add(Controller.class); return s; } @RequestMapping(value = "http ://localhost:8080/restapps-0.0.1-SNAPSHOT/restapp/test/{id}", method = RequestMethod.GET) public String getWelcome(@PathVariable(value = "id") String id) { return "Welcome to jax-rs " + id; } } 

ApplicationConfig is an empty class that extends Application.

Thanks for any tips / answers.

  • The Tomcat log simply shows a lot of my requests and 404 for each. - WildTigerrr
  • see if there is any application with jars inside Tomcata at all - AdamSkywalker
  • @AdamSkywalker is so interesting, but you can also ask how to make maven-war-plugin pack all my classes into the archive, and not just the settings and what Maven imported? - WildTigerrr
  • did not work with him. if not packed, it is possible that the path is not transferred to it from where the classes of the project are taken. - AdamSkywalker
  • @AdamSkywalker packaged, but it did not change anything. However, tomorrow I will also try to dig in this direction, maybe I was close to the solution, but since protupil in this moment nothing came out, thank you. - WildTigerrr

1 answer 1

There are a few comments to your decision:

  1. The components of the Spring Framework must be atomic, and the connections between them must be strictly through IoC.

  2. Configurations and components are different things. Even between configuration classes, no inheritance is assumed (via @Import). And, really, it is not necessary to inherit the controller from the config.

  3. Regarding the deployment in the usual Tomcat. Keep in mind that Tomcat is a servlet container, which means that each application must implement the servlet standard. In the case of Spring Boot, simply inherit the Application from the SpringBootServletInitializer and compile the WAR archive. After deploying to Tomcat, you will get a traditional application with the Spring Framework context initialized. Details can be found in the documentation.

  • Inheritance from SpringBootServletInitializer solved the problem. - WildTigerrr