grails-core: Deploying war to tomcat fails for grails 5.1.2

Expected Behavior

Expecting that the war should deploy to tombat without errors. This did not work in version 5.1.1 either.

Actual Behaviour

20-Jan-2022 12:59:35.530 ALLVARLIG [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Gradle___se_su_it___vfuportalen_war]]
	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.deployDirectory(HostConfig.java:1141)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
	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:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groovyPagesTemplateEngine': Cannot resolve reference to bean 'classLoader' while setting bean property 'classLoader'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'classLoader' available
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1707)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1452)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
	at org.grails.boot.context.web.GrailsAppServletInitializer.createRootApplicationContext(GrailsAppServletInitializer.groovy:58)
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	... 10 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'classLoader' available
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:872)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1344)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:309)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330)
	... 32 more

Steps To Reproduce

No response

Environment Information

Mac OS Monterey and and our ci-system running Debian Linux Java 1.8 Tomcat 8.5.27

Example Application

No response

Version

5.1.2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I had to exclude also module ‘grails-shell’ from dependencies. Because it includes spring-boot-cli which has own WebApplicationInitializer and usually it will start war from from it, not from GrailsAppServletInitializer.

Caused by: java.lang.NullPointerException
		at org.springframework.boot.cli.app.SpringApplicationWebApplicationInitializer.getSources(SpringApplicationWebApplicationInitializer.java:61)

@Dirk-27 I was running into this root cause when using gradle war deployed to tomcat. I traced the issue to developmentOnly dependencies being included in the war. According to this spring boot documentation, the spring boot gradle plugin now defines productionRuntimeClasspath for this purpose. In org.springframework.boot.gradle.plugin.WarPluginAction you can see the plugin removing developmentOnly dependencies from the war classpath.

I added a block similar to this to my build file and no longer have issues with developmentOnly dependencies in my war file.

war {
	def springBootCLI = classpath.find { it.name.contains("spring-boot-cli-") }//known problem package
	if( springBootCLI ) {
		// org.springframework.boot.gradle.plugin.WarPluginAction
		logger.warn("WAR classpath contains developmentOnly packages.  removing")
		classpath = classpath.minus(
			configurations.developmentOnly.minus(
				configurations.productionRuntimeClasspath
			)
		)
	} else {
		logger.trace("WAR classpath fine")
	}
}

We have been having the same problem as @Dirk-27 (with a very similar stacktrace) after upgrading several apps to Grails 5, but @scottlollman’s solution didn’t work out. Finally found a similar solution here that did the trick for us:

Using that solution (updating the plugin call to implementation ('org.grails.plugins:database-migration:4.2.1') { exclude module: 'spring-boot-cli' }) excludes the troublesome spring-boot-cli, allowing startup and migrations to proceed normally.