Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodError when deploying to Tomcat 8.5 before 8.5.44 and Tomcat 9 before 9.0.23 #19308

Closed
wilkinsona opened this issue Dec 5, 2019 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wilkinsona
Copy link
Member

From this question on Stack Overflow:

2019 12 05 14:05:45#+00#ERROR#org.apache.catalina.core.ContainerBase##anonymous#localhost-startStop-1#na#s2k4640ult#permitmgmtcoreaic#web##na#na#na#na#ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/permitmgmt-core]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:836)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.apache.catalina.valves.RemoteIpValve.setHostHeader(Ljava/lang/String;)V
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:152)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:132)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:92)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5245)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.apache.catalina.valves.RemoteIpValve.setHostHeader(Ljava/lang/String;)V
    at org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer.customizeRemoteIpValve(TomcatWebServerFactoryCustomizer.java:189)
    at org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer.customize(TomcatWebServerFactoryCustomizer.java:85)
    at org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactoryCustomizer.customize(TomcatWebServerFactoryCustomizer.java:60)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.lambda$postProcessBeforeInitialization$0(WebServerFactoryCustomizerBeanPostProcessor.java:72)
    at org.springframework.boot.util.LambdaSafe$Callbacks.lambda$null$0(LambdaSafe.java:287)
    at org.springframework.boot.util.LambdaSafe$LambdaSafeCallback.invoke(LambdaSafe.java:159)
    at org.springframework.boot.util.LambdaSafe$Callbacks.lambda$invoke$1(LambdaSafe.java:286)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1082)
    at org.springframework.boot.util.LambdaSafe$Callbacks.invoke(LambdaSafe.java:286)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.postProcessBeforeInitialization(WebServerFactoryCustomizerBeanPostProcessor.java:72)
    at org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor.postProcessBeforeInitialization(WebServerFactoryCustomizerBeanPostProcessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1795)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
    ... 28 common frames omitted

This is caused by the changes for #18233 and the fact that the web server factory customisers run, even though the factory that the customize is never used. We had a similar problem in the past. We could catch the NoSuchMethodError and assume an earlier version of Tomcat, but it would be nicer if the customizers weren't called at all.

@wilkinsona wilkinsona added this to the 2.2.x milestone Dec 5, 2019
@wilkinsona wilkinsona added type: bug A general bug for: team-attention An issue we'd like other members of the team to review labels Dec 5, 2019
@philwebb philwebb self-assigned this Dec 6, 2019
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Dec 6, 2019
@philwebb philwebb assigned wilkinsona and unassigned philwebb Dec 6, 2019
@niiick1
Copy link

niiick1 commented Dec 18, 2019

@wilkinsona Is there a workaround for this considering I can't update Tomcat?

@wilkinsona
Copy link
Member Author

@niiick1 You may be able to use a BeanFactoryPostProcessor to remove the unwanted customizer:

@Bean
public static BeanFactoryPostProcessor removeTomcatWebServerCustomizer() {
    return (beanFactory) -> 
        ((DefaultListableBeanFactory)beanFactory).removeBeanDefinition("tomcatWebServerFactoryCustomizer");
}

@niiick1
Copy link

niiick1 commented Dec 18, 2019

@wilkinsona Thanks, that works! :)

Is there anything I miss for not running the customizer?

@wilkinsona
Copy link
Member Author

wilkinsona commented Dec 18, 2019

Excellent. Thanks for letting us know. You won't be missing anything as the factory that is customized isn't actually used when deploying a war file to a container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants