2

I have converted a classic spring framework application to Spring Boot, and now I getting this:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.3.RELEASE)

2016-04-07 08:32:47.588  INFO 2448 --- [           main] b.c.j.besser.core.BesserCoreApplication  : Starting BesserCoreApplication on roberton with PID 2448 (D:\JJW\srcBesser\besser-core\target\classes started by Roberto in D:\JJW\srcBesser\besser-core)
2016-04-07 08:32:47.599  INFO 2448 --- [           main] b.c.j.besser.core.BesserCoreApplication  : No active profile set, falling back to default profiles: default
2016-04-07 08:32:48.059  INFO 2448 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@47d9a273: startup date [Thu Apr 07 08:32:48 BRT 2016]; root of context hierarchy
2016-04-07 08:32:51.815  INFO 2448 --- [           main] o.s.s.a.AsyncAnnotationBeanPostProcessor : No TaskExecutor bean found for async annotation processing.
2016-04-07 08:32:52.114  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c59662e5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.506  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [class org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.517  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@2bbb44da' of type [class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.543  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [class org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$78749757] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.604  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [class org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.644  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$9c7519eb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:52.760  INFO 2448 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [class org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$3d2e449] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-04-07 08:32:54.537  INFO 2448 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-04-07 08:32:54.564  INFO 2448 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-04-07 08:32:54.566  INFO 2448 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.32
2016-04-07 08:32:55.770  INFO 2448 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-04-07 08:32:55.778  INFO 2448 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-04-07 08:32:55.779  INFO 2448 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 7727 ms
2016-04-07 08:32:57.002  INFO 2448 --- [g-Init-Reporter] com.mchange.v2.log.MLog                  : MLog clients using slf4j logging.
2016-04-07 08:32:57.093  INFO 2448 --- [ost-startStop-1] com.mchange.v2.c3p0.C3P0Registry         : Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]
2016-04-07 08:32:57.926  INFO 2448 --- [ost-startStop-1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'pu'
2016-04-07 08:32:57.957  INFO 2448 --- [ost-startStop-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: pu
    ...]
2016-04-07 08:32:58.158  INFO 2448 --- [ost-startStop-1] org.hibernate.Version                    : HHH000412: Hibernate Core {4.3.11.Final}
2016-04-07 08:32:58.163  INFO 2448 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-04-07 08:32:58.167  INFO 2448 --- [ost-startStop-1] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-04-07 08:32:58.750  INFO 2448 --- [ost-startStop-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-04-07 08:32:59.079  INFO 2448 --- [ost-startStop-1] c.m.v.c.i.AbstractPoolBackedDataSource   : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 30000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1b61c019f1uq94rx1amrowc|b5a3aa3, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.firebirdsql.jdbc.FBDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1b61c019f1uq94rx1amrowc|b5a3aa3, idleConnectionTestPeriod -> 300, initialPoolSize -> 2, jdbcUrl -> jdbc:firebirdsql:192.168.15.250:/datasource/patomuxi/mercotoys.fdb?encoding=ISO8859_1, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 900, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> select first 1 1 from RDB$DATABASE, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
2016-04-07 08:32:59.115  WARN 2448 --- [ost-startStop-1] c.m.v2.resourcepool.BasicResourcePool    : Bad pool size config, start 2 < min 3. Using 3 as start.
2016-04-07 08:32:59.854  INFO 2448 --- [ost-startStop-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.FirebirdDialect
2016-04-07 08:33:00.992  INFO 2448 --- [ost-startStop-1] o.h.h.i.ast.ASTQueryTranslatorFactory    : HHH000397: Using ASTQueryTranslatorFactory
2016-04-07 08:33:16.722  INFO 2448 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-04-07 08:33:16.725  INFO 2448 --- [ost-startStop-1] .e.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2016-04-07 08:33:16.725  INFO 2448 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'tokenAuthenticationFilter' to: [/*]
2016-04-07 08:33:16.725  INFO 2448 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-04-07 08:33:17.409  INFO 2448 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4fd33ae3, org.springframework.security.web.context.SecurityContextPersistenceFilter@7835caf0, org.springframework.security.web.header.HeaderWriterFilter@4ea80253, org.springframework.security.web.authentication.logout.LogoutFilter@5d0beb29, br.com.jjw.besser.core.authentication.TokenAuthenticationFilter@63293d93, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@737d8efb, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1b678950, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@43f05caf, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2afe0b48, org.springframework.security.web.session.SessionManagementFilter@82e98a2, org.springframework.security.web.access.ExceptionTranslationFilter@2c14c825, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3c2b82e3]
2016-04-07 08:33:25.841  WARN 2448 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [br/com/jjw/besser/core/configuration/MvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
2016-04-07 08:33:25.869  INFO 2448 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'pu'
2016-04-07 08:33:25.879  INFO 2448 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-04-07 08:33:25.897 ERROR 2448 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [br/com/jjw/besser/core/configuration/MvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at br.com.jjw.besser.core.BesserCoreApplication.main(BesserCoreApplication.java:15) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    ... 18 common frames omitted
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
    at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.<init>(DefaultServletHandlerConfigurer.java:53) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:451) ~[spring-webmvc-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at br.com.jjw.besser.core.configuration.MvcConfiguration$$EnhancerBySpringCGLIB$$cb14c397.CGLIB$defaultServletHandlerMapping$23(<generated>) ~[classes/:na]
    at br.com.jjw.besser.core.configuration.MvcConfiguration$$EnhancerBySpringCGLIB$$cb14c397$$FastClassBySpringCGLIB$$1f6cf842.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at br.com.jjw.besser.core.configuration.MvcConfiguration$$EnhancerBySpringCGLIB$$cb14c397.defaultServletHandlerMapping(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    ... 19 common frames omitted

This is the root of the cause, the messageSource bean:

@Configuration
public class MvcConfiguration extends WebMvcConfigurationSupport {

    @Bean(name = "messageSource")
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messages = new ReloadableResourceBundleMessageSource();
        messages.setBasenames("classpath:beanValidation", "classpath:errors");
        messages.setDefaultEncoding("UTF-8");
        return messages;
    }

    @Override
    protected Validator getValidator() {
        LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
        validator.setValidationMessageSource(messageSource());
        return validator;
    }
}

When I rename the messageSource method to messageSource2 it works, but I'm not abble to use my LocalizedMessageService that autowire the default MessageSource to query for my custom messages.

How can I add custom message base names to the default MessageSource?

6
  • have you added any servlet mapping or @Servlet,@Configuration annotation? also have a look at br.com.jjw.besser.core.BesserCoreApplication.main(BesserCoreApplication.java:15) Commented Apr 7, 2016 at 11:42
  • You might also want to have a look at this spring.io/guides/gs/spring-boot.. because you haven't shared your code it's difficult to assess what you are missing. Commented Apr 7, 2016 at 11:45
  • 1
    In order to get some help please share at least your configuration files that bootstrap your application Commented Apr 7, 2016 at 12:05
  • 1
    Add your MvcConfiguration class. I'm guessing that you're trying to use configureDefaultServletHandling method. Commented Apr 7, 2016 at 12:25
  • I have felt this pain before - stackoverflow.com/questions/33832792/… Good Luck Commented Apr 7, 2016 at 13:11

1 Answer 1

7

Solved.

I have separated the messageSource bean from the MvcConfiguration, I put it inside another configuration class:

@Configuration
public class LocalizationConfiguration {

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messages = new ReloadableResourceBundleMessageSource();
        messages.setBasenames("classpath:beanValidation", "classpath:errors");
        messages.setDefaultEncoding("UTF-8");
        return messages;
    }

}

Aparently, my WebMvcConfigurationSupport extension cannot instantiate the messageSource.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for sharing a solution. How do you use it in your getValidator() method now? You have a field of type LocalizationConfiguration in your MvcConfiguration class?
I haven't defined an Validator, I'm using the Spring Boot auto configurator for instantiate the validador. You just need to have hibernate-validator in your class path and the spring takes care about using the messageSource bean as the source of your localization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.