I have a Spring boot application and want to run this as a server app within Eclipse. So the app will be recognized as a Tomcat web app and can be added I update the facet :
When I run the web app my rest services are not being found. A spring boot app contains a different folder structure than spring apps before spring boot was released. Can a spring boot app be run from an eclipse configured tomcat ? Also prior to spring boot the controllers section of the app needs to specified. Do I need to update my spring boot app with these settings in order to run from Eclipse tomcat ?
I don't want to create a war and then copy it to webapps folder of tomcat.
Update : The reason to run this app within Eclipse tomcat container is that I have other non spring boot applications that my new spring boot app will depend on.
Check your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Then check your main app class:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Then configure Project Facets (as you have already did):
Then check your Deployment Assembly:
Done!
eclipse-wtp
and war
SpringBootServletInitializer
in Application
In order to run a spring boot application on tomcat generally the produced artifact has to be a war
application.
In order to make it run on tomcat inside Eclipse you have to use a WTP-Project (Web Tools Platform aka Dynamic Web Module) using the eclipse-wtp
gradle plugin.
The SpringBootServletInitializer
thing has to be extended in order to make Spring Boot application context launch when Tomcat is launched.
Spring offers a Getting Started Tutorial how to build a REST webservice with Spring Boot. I enhanced the project to work with Tomcat and Eclipse:
the sample project:
git clone https://github.com/spring-guides/gs-rest-service.git
Import the complete/
subfolder as gradle project.
build.gradle
remove
apply plugin: 'java'
apply plugin: 'eclipse'
add
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
src/main/java/hello/Application.java
add extension of SpringBootServletInitializer
public class Application extends SpringBootServletInitializer {
...
}
That done I could deploy the sample project to a Tomcat server configured in eclipse and start the server. The url is: http://localhost:8080/complete/greeting?name=User
Check out the Complete Sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With