spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Application startup failed after Spring Boot upgrade to 2.0.0.BUILD-20161220.024734-219

Open r9yn opened this issue 9 years ago • 13 comments

2016-12-20 13:20:40.665  INFO 12300 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-12-20 13:20:40.666  INFO 12300 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-12-20 13:20:40.684  WARN 12300 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NullPointerException
2016-12-20 13:20:40.689  INFO 12300 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-12-20 13:20:40.716  WARN 12300 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2016-12-20 13:20:40.729  WARN 12300 --- [  restartedMain] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.annotation.ProxyCachingConfiguration': Initialization of bean failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' available)
2016-12-20 13:20:40.737 ERROR 12300 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:577)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:484)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:749)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:736)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1161)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1150)
    at com.test.Application.main(Application.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NullPointerException: null
    at org.aspectj.weaver.ResolvedType.lookupResolvedMember(ResolvedType.java:627)
    at org.aspectj.weaver.JoinPointSignatureIterator.findSignaturesFromSupertypes(JoinPointSignatureIterator.java:192)
    at org.aspectj.weaver.JoinPointSignatureIterator.hasNext(JoinPointSignatureIterator.java:68)
    at org.aspectj.weaver.patterns.SignaturePattern.matches(SignaturePattern.java:317)
    at org.aspectj.weaver.patterns.KindedPointcut.matchInternal(KindedPointcut.java:197)
    at org.aspectj.weaver.patterns.Pointcut.match(Pointcut.java:137)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.getShadowMatch(PointcutExpressionImpl.java:319)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesExecution(PointcutExpressionImpl.java:129)
    at org.aspectj.weaver.internal.tools.PointcutExpressionImpl.matchesMethodExecution(PointcutExpressionImpl.java:110)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getShadowMatch(AspectJExpressionPointcut.java:422)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:276)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:241)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:279)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:311)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1614)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:568)
    ... 20 common frames omitted

r9yn avatar Dec 20 '16 05:12 r9yn

all my custom codes works well with version '2.0.0.BUILD-SNAPSHOT' before 2016-12-19

r9yn avatar Dec 20 '16 05:12 r9yn

Thanks but it's going to be hard for us to guess what is wrong without a sample. Can you provide one please?

snicoll avatar Dec 20 '16 07:12 snicoll

Can you override the AspectJ version to 1.8.9 and check if the error goes away?

If you are using maven and the spring-boot-starter-parent something like:

<properties>
  <aspectj.version>1.8.9</aspectj.version>
</properties>

snicoll avatar Dec 20 '16 11:12 snicoll

Managed to bypass it by downgrading aspectjweaver to 1.8.9 Add this dependency to your Gradle file if you are using one compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.9'

yuvalbo avatar Dec 20 '16 13:12 yuvalbo

See #7705

snicoll avatar Dec 20 '16 14:12 snicoll

Great! downgrade aspectjweaver to 1.8.9 works

r9yn avatar Dec 20 '16 14:12 r9yn

Hi,

I am still getting this error. Here is my complete trace posted on stackoverflow. Can anybody please help me on this ?

https://stackoverflow.com/questions/46548056/error-creating-bean-with-name-resourcehandlermapping-defined-in-class-path-res

PS: I added <aspectj.version>1.8.10</aspectj.version> but still no luck.

I believe that below bean is not setting the servletContext and its failing for resourceMappingHandler

@Bean
public ContentNegotiationManager mvcContentNegotiationManager() {
	if (this.contentNegotiationManager == null) {
		ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer(this.servletContext);
		configurer.mediaTypes(getDefaultMediaTypes());
		configureContentNegotiation(configurer);
		try {
			this.contentNegotiationManager = configurer.getContentNegotiationManager();
		}
		catch (Throwable ex) {
			throw new BeanInitializationException("Could not create ContentNegotiationManager", ex);
		}
	}
	return this.contentNegotiationManager;
}

ab48917 avatar Oct 10 '17 12:10 ab48917

I am getting below errors. It seems servlet context is not coming up for spring 5 with boot 2.0.0 Do I manually need to setup servletContext for this? I believe spring boot setup automatically web environment.

Caused by: java.lang.IllegalStateException: No ServletContext set
	at org.springframework.util.Assert.state(Assert.java:73) ~[spring-core-5.0.0.RC4.jar:5.0.0.RC4]
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:480) ~[spring-webmvc-5.0.0.RC4.jar:5.0.0.RC4]
	at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$e8513177.CGLIB$resourceHandlerMapping$36(<generated>) ~[spring-boot-autoconfigure-2.0.0.M4.jar:2.0.0.M4]
	at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$e8513177$$FastClassBySpringCGLIB$$fe3dab6b.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.0.M4.jar:2.0.0.M4]
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.0.RC4.jar:5.0.0.RC4]
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.0.RC4.jar:5.0.0.RC4]
	at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$e8513177.resourceHandlerMapping(<generated>) ~[spring-boot-autoconfigure-2.0.0.M4.jar:2.0.0.M4]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
	at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:155) ~[spring-beans-5.0.0.RC4.jar:5.0.0.RC4]
	... 20 common frames omitted

ab48917 avatar Oct 11 '17 12:10 ab48917

@ab48917 The same error. Did found a solution?

richardlyc avatar Feb 24 '18 09:02 richardlyc

HI rich,

Yes. Please clean your .m2 or .gradle directory or delete and build the application again. It should be working fine.

On Sat, Feb 24, 2018 at 3:30 PM, richardlyc [email protected] wrote:

@ab48917 https://github.com/ab48917 The same error. Did found a solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/7699#issuecomment-368216774, or mute the thread https://github.com/notifications/unsubscribe-auth/AaFtbIhNt4E6TRnLE08lkg2l4kh-YlDLks5tX92ugaJpZM4LRepj .

ab48917 avatar Feb 24 '18 10:02 ab48917

@ab48917 After clean .gradle, the error is still the same.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set

After debugging, the problem is that mvc configuration class EnableWebMvcConfiguration load too early, servlet not loaded yet. I'm still looking for a solution

richardlyc avatar Feb 25 '18 08:02 richardlyc

It seems some hibernate-validator or validation-api jars conflict. can you please check what all versions of jars do you have ? I had conflict with jars versions since I was using spring mvc 4.3 and my hibernate validator was of older version in weblogic. so I updated the jars in weblogic lib to latest validator and hibernnate jars and it solved for me. You need to look at the jars compatibility. It seems It is tring to load some class which isn't available in your current context lib.

On Sun, Feb 25, 2018 at 2:13 PM, richardlyc [email protected] wrote:

@ab48917 https://github.com/ab48917 After clean .gradle, the error is still the same.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set

After debugging, the problem is that mvc configuration class EnableWebMvcConfiguration load too early, servlet not loaded yet. I'm still looking for a solution

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/7699#issuecomment-368292847, or mute the thread https://github.com/notifications/unsubscribe-auth/AaFtbDERHGeD_XZ3npKTV23fQz-E5_94ks5tYR08gaJpZM4LRepj .

ab48917 avatar Feb 25 '18 12:02 ab48917

I found the code that caused the exception.

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true, proxyTargetClass = true)
public class MethodSecurityConfiguration extends GlobalMethodSecurityConfiguration {

    @Autowired
    private RoleHierarchy roleHierarchy;

    @Override
    protected MethodSecurityExpressionHandler createExpressionHandler() {

        OAuth2MethodSecurityExpressionHandler expressionHandler =
                new OAuth2MethodSecurityExpressionHandler();

        expressionHandler.setRoleHierarchy(roleHierarchy);

        return expressionHandler;
    }
}

Comment out “expressionHandler.setRoleHierarchy(roleHierarchy);”, exception disappear. Before spring boot 2.0 everything is fine. After start expression handler, meet mvc auto-configuration condition. I think it may be. Thank you for your help.

richardlyc avatar Feb 26 '18 08:02 richardlyc