I am trying to create a war with Gradle and deploy it on an existing Tomcat.
I succeeded in creating war, but when I put it on the webapp and launch Tomcat, I get the following error:
Critical [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternalContainerBase.addChild:start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine [Catalina].StandardHost [localhost].StandardContext [/app]]
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal (ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild (ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild (StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR (HostConfig.java:986)
at org.apache.catalina.startup.HostConfig$DeployWar.run (HostConfig.java:1857)
at java.util.current.Executors$RunableAdapter.call (Executors.java:511)
at java.util.current.FutureTask.run (FutureTask.java:266)
at java.util.current.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.current.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalStateException: Duplicate Filter registration for 'springSecurityFilterChain'. Check to enable the Filter is only configured once.
at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.registerFilter(AbstractSecurityWebApplicationInitializer.java:217)
at org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.insertSpringSecurityFilterChain (AbstractSecurityWebApplicationInitializer.java:151)
at org.springframework.security.web.context.AbstractSecurityWebApplicationInitialize.onStartup (AbstractSecurityWebApplicationInitialize.java:124)
at org.springframework.web.SpringServletContainerInitializer.onStartup (SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150)
... 10 more
When running with eclipse, I use Tomcat included in SpringBoot and it works fine.
The version is specified except for Tomcat, which is enbed to match the version with Tomcat on the server.
In addition, Gradle defines that Tomcat's jar is not included when creating war.
buildscript{
ext{
springBootVersion='1.5.9.RELEASE'
tomcatVersion='8.5.24'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
version = '0.0.0 - SNAPSHOT'
sourceCompatibility=1.8
repositories {
mavenCentral()
}
[compileJava,compileTestJava]*.options*.encoding='UTF-8'
processResources.destinationDir=compileJava.destinationDir
compileJava.dependsOnprocessResources
dependencies {
compile('org.springframework.boot:spring-boot-starter-web'){
exclude (module: 'spring-boot-starter-tomcat')
exclude(group: 'org.apaceh.tomcat.embed')
}
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-mail')
providedCompile("org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}")
providedCompile("org.apache.tomcat.embed:tomcat-embed-el:${tomcatVersion}")
providedCompile("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}")
providedCompile('org.apache.tomcat.embed:tomcat-embed-logging-juli:8.5.2')
providedCompile("org.apache.tomcat.embed:tomcat-embed-websocket:${tomcatVersion}")
providedCompile(" org.apache.tomcat:tomcat-jdbc:${tomcatVersion}")
providedCompile(" org.apache.tomcat:tomcat-jsp-api:${tomcatVersion}")
compile('org.tymeleaf.extras:tymeleaf-extras-springsecurity4')
compile('org.projectlombok:lombok:1.16.16')
compile('org.postgresql:postgresql:9.3-1100-jdbc4')
compile('org.seasar.doma.boot:domain-spring-boot-start:1.1.0')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
war{
archiveName 'app.war';
}
Tomcat logs show that the Spring Security filter is duplicated, but only one Config class is involved in the SpringSecurity FilterChain configuration in the project.
...abbreviated
@Configuration
@ EnableWebSecurity
public class AppWebSecurityConfigurer extensions WebSecurityConfigurerAdapter {
@Autowired
AppLogoutHandler logoutHandler;
@Autowired
AppLoginSuccessHandler loginSuccessHandler;
@Autowired
LoginService loginService;
@ Bean
AppLoginSuccessHandler loginSuccessHandler(){
return new AppLoginSuccessHandler();
}
@ Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@ Override
protected void configure(HttpSecurity http)throws Exception {
http.authorizeRequests()
.antMatchers("/app/auth/**")
.authenticated()
.antMatchers("/js/**"
, "/css/**"
, "/images/**"
, "/vendor/**"
, "/app/**")
.permitAll()
.and()
.formLogin()
.loginPage(URL_LOGIN)
.usernameParameter ("username")
.passwordParameter ("password")
.successHandler (loginSuccessHandler)
.failureUrl(URL_LOGIN+"?error=true")
.permitAll()
.and()
.logout()
.logoutRequestMatcher (new AntPathRequestMatcher(U_LOGOUT))
.logoutSuccessUrl(U_HOME_INDEX)
.deleteCookies ("JSESSIONID")
.addLogoutHandler(logoutHandler)
.invalidateHttpSession(true)
.permitAll()
.and()
.sessionManagement()
.sessionFixation()
.newSession()
.invalidSessionUrl(URL_LOGIN);
}
@ Override
protected void configure(AuthenticationManagerBuilder auth)throws Exception {
auth.userDetailsService(loginService).passwordEncoder(passwordEncoder());
}
}
Because of my ignorance, I don't know where to look, so I'm asking you a question.
If anyone knows, please let me know.
I solved myself.
Initializer failed to specify SpringSecurity Config class.
public class AppSecurityWebApplicationInitializer extensions AbstractSecurityWebApplicationInitializer{
public AppSecurityWebApplicationInitializer(){
super(AppWebSecurityConfigurer.class);
}
/// Override method ///
}
However, if you are using Spring or SpringMVC, the initializer you were running earlier was loading @Configuration, so it seemed to be configured in duplicate.
I haven't even looked into why the built-in Tomcat works, but it's a resolution for now.
© 2024 OneMinuteCode. All rights reserved.