Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot and tomcat

I would like to see a spring boot sample that lets me do:

mvn tomcat:run

I tried existing samples and following tutorials but with no luck.

like image 723
piotrek Avatar asked Dec 09 '25 19:12

piotrek


1 Answers

The official documentation is not very clear about this, but I've found this concise and easy how-to to put spring boot and tomcat maven plugin all together.

https://gerrydevstory.com/2014/08/22/spring-boot-and-the-embedded-tomcat-container/

The gist of the information on the site:

  • Remove spring-boot-maven-plugin <plugin> configuration on pom.xml

  • Setup tomcat7-maven-plugin <plugin>

.

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.0</version>
</plugin>
  • Instead of SpringApplication.run(Application.class, args), bootstrap Spring Boot using SpringBootServletInitializer instead, eg:

.

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
  }

}

And change the scope in POM.xml

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <scope>provided</scope>
</dependency>
like image 188
JR Utily Avatar answered Dec 12 '25 09:12

JR Utily



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!