Thứ Hai, 2 tháng 11, 2015

Sping Boot: run with Maven Tomcat

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

The configuration for run Spring Boot project with Maven Tomcat is written in above link.
1). Remove spring-boot-maven-plugin <plugin> configuration on pom.xml
2). Setup tomcat7-maven-plugin <plugin>
<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat7-maven-plugin</artifactId>
  <version>2.0</version>
</plugin>


3). Instead of SpringApplication.run(Application.class, args), bootstrap Spring Boot using SpringBootServletInitializer instead
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends SpringBootServletInitializer {
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
  }
   
}


4). marking spring-boot-started-tomcat as provided in the dependencies in pom.xml
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>


Bugs:
1)
at 2) section, tomcat7-maven-plugin's version 2.0 with jdk 8 will throw error "The type java.util.Map$Entry cannot be resolved."

Link: http://stackoverflow.kcom/a/21322569
Change version to 2.2, to fix it.

2)
Error:
Cannot forward to error page for request [/] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false

Fix:
Link: http://stackoverflow.com/a/31858680
Add to Application class at 3) section

@Bean
public ErrorPageFilter errorPageFilter() {
    return new ErrorPageFilter();
}

@Bean
public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(filter);
    filterRegistrationBean.setEnabled(false);
    return filterRegistrationBean;
}

Continue ...
- Comments

0 nhận xét:

Đăng nhận xét