Problems with EJB injection when use Quartz and JBoss 5.0.1 - ejb

I need to configure a process that it execute when start the server JBoss 5.0.1. I have the next class:
#MessageDriven(activationConfig =
{
#ActivationConfigProperty(propertyName="cronTrigger", propertyValue="0 0/1 * * * ?")
})
#ResourceAdapter("quartz-ra.rar")
public class SincronizadorProcesosEnEspera implements Job
{
// #EJB(mappedName=Constants.EJB_MAPPED_FACADE_ADMINISTRADOR_LOCAL) <----------I try with this other way, and nothing
private IAdministradorFacade administradorFacade;
public void execute(JobExecutionContext arg0) throws JobExecutionException
{
// administradorFacade = (IAdministradorFacade) JNDIResources.getAdministradorFacade(); <-------------------I try with this other way, and nothing
// administradorFacade =(IAdministradorFacade) BeanContextUtil.getBean("administradorFacade"); <------------------I try with this other way, and nothing
administradorFacade.sincronizarProcesos();<--------- When pass for this point throw a error
}
}
The error that throw the aplicattion is this:
11:38:00,066 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound
11:38:00,066 ERROR [JobRunShell] Job default.job.0.1351010259957 threw an unhandled Exception:
javax.ejb.EJBTransactionRolledbackException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:80)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:262)
at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:270)
at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:140)
at $Proxy351.execute(Unknown Source)
at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.RuntimeException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound
at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:82)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:89)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:61)
at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:89)
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:83)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:74)
at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1086)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:83)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:73)
at org.jboss.ejb3.pool.StrictMaxPool.get(StrictMaxPool.java:145)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
... 17 more
Caused by: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: ejb not bound]
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1348)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:813)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)
at org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
... 31 more
Caused by: javax.naming.NameNotFoundException: ejb not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1342)
... 35 more
11:38:00,066 ERROR [ErrorLogger] Job (default.job.0.1351010259957 threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: javax.ejb.EJBTransactionRolledbackException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound]
at org.quartz.core.JobRunShell.run(JobRunShell.java:214)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
* Nested Exception (Underlying Cause)
javax.ejb.EJBTransactionRolledbackException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:194)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:80)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:262)
at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:270)
at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:140)
at $Proxy351.execute(Unknown Source)
at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
Caused by: java.lang.RuntimeException: Unable to inject jndi dependency: env/com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera/administradorFacade into property com.integra.ppo.modelo.administrador.scheluder.SincronizadorProcesosEnEspera.administradorFacade: ejb not bound
at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:82)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:89)
at org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:61)
at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:89)
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:83)
at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:74)
at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1086)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:83)
at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:73)
at org.jboss.ejb3.pool.StrictMaxPool.get(StrictMaxPool.java:145)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
... 17 more
Caused by: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: ejb not bound]
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1348)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:813)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)
at org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
at org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75)
... 31 more
Caused by: javax.naming.NameNotFoundException: ejb not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1342)
... 35 more
---Please, help me, Only I need to execute a process with Quartz but the EJB cant be injected, The EJB is declarate in spring like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<jee:local-slsb id="administradorFacade"
jndi-name="ModeloAdministradorEAR/AdministradorFacade/local"
business-interface="com.integra.ppo.modelo.administrador.facade.IAdministradorFacadeLocal"
cache-home="true" lookup-home-on-startup="true" resource-ref="true" />
</beans>
Thanks

Related

How to configure springfox to use Gson instead of Jackson

I am trying to use Gson to send JsonObjects as response. These JsonObjects are constructed manually instead of using objectMapper or Gson. I excluded all the dependencies related to Jackson. It works well and good. Later I tried to add Swagger documentation using springfox. Now it throws below exceptions:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in springfox.documentation.spring.web.SpringfoxWebMvcConfiguration: Post-processing of merged bean definition failed; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:235) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) ~[spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
at com.honeywell.ldi.LdiDetailerApplication.main(LdiDetailerApplication.java:44) ~[classes/:na]
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_151]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_151]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_151]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489) ~[spring-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:206) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:187) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:125) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:295) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:992) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_151]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_151]
... 26 common frames omitted
The exception is due to springfox.documentation.spring.web.ObjectMapperConfigurer
complaining about missing com.fasterxml.jackson.databind.ObjectMapper.
The ObjectMapper exists in com.fasterxml.jackson.core:jackson-databind:jar. You would still need jackson-databind JAR to make your application work with Springfox.
As for SpringFox, it doesn't work with Gson out of the box. You need to register custom serializers for different Springfox artifacts with the Gson object.
Gson gson = GsonBuilder()
// needed for making calls to /v2/api-docs
.registerTypeAdapter(Json.class,
new SpringfoxJsonSerializer())
// rest are needed for making calls to /swagger-ui.html
.registerTypeAdapter(ApiListing.class,
new SpringfoxApiListingJsonSerializer())
.registerTypeAdapter(SwaggerResource.class,
new SpringfoxResourceJsonSerializer())
.registerTypeAdapter(ResourceListing.class,
new SpringfoxResourceListingJsonSerializer())
.registerTypeAdapter(UiConfiguration.class,
new SpringfoxUiConfigurationJsonSerializer())
// needed if you have security
.registerTypeAdapter(SecurityConfiguration.class,
new SpringfoxSecurityConfigurationJsonSerializer())
...
.create();
Here is a working example with Spring Boot, SpringFox, and Gson.

'java.lang.IllegalStateException: A ServletContext is required to access the javax.websocket.server.ServerContainer instance' Error occurs

I have this error when run junit test in spring mvc project.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createWebSocketContainer' defined in net.ebaolife.tpa.websocket.WebSocketConfig: Invocation of init method failed; nested exception is java.lang.IllegalStateException: A ServletContext is required to access the javax.websocket.server.ServerContainer instance
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:732)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 24 more
Caused by: java.lang.IllegalStateException: A ServletContext is required to access the javax.websocket.server.ServerContainer instance
at org.springframework.util.Assert.state(Assert.java:392)
at org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean.afterPropertiesSet(ServletServerContainerFactoryBean.java:102)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 39 more
I have add below jar. And spring version is 4.3.3.RELEASE
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.0.28</version>
<scope>test</scope>
</dependency>
I found this bug in spring forum https://jira.spring.io/browse/SPR-14367.
But it only provided a workaround in spring boot, and it says it is fixed in spring 4.3.1 .
Test class is :
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration({ "classpath*:applicationContext*.xml" })
public class Test {
...
}
In test class add annotation #WebAppConfiguration, this error is gone.

Arquillian Test

I am getting the following exception:
org.jboss.arquillian.container.spi.client.container.DeploymentException: Cannot deploy: test.war
at org.jboss.as.arquillian.container.ArchiveDeployer.deployInternal(ArchiveDeployer.java:83)
...
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)Caused by: java.lang.Exception: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"test.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test.war\".WeldStartService: Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001414: Bean name is ambiguous. Name enumBean resolves to beans:-Managed Bean [class br.mil.eb.cds.sil.comum.interfaces.EnumBean] with qualifiers [#Any #Default],- Managed Bean [class br.mil.eb.cds.sil.comum.interfaces.EnumBean] with qualifiers [#Any #Default]"}}
at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.getActionResult(ServerDeploymentPlanResultFuture.java:134)
at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.getResultFromNode(ServerDeploymentPlanResultFuture.java:123)
at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.get(ServerDeploymentPlanResultFuture.java:85)
at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.get(ServerDeploymentPlanResultFuture.java:42)
at org.jboss.as.controller.client.helpers.standalone.ServerDeploymentHelper.deploy(ServerDeploymentHelper.java:55)
at org.jboss.as.arquillian.container.ArchiveDeployer.deployInternal(ArchiveDeployer.java:77)
... 88 more
I am using arquillian platform for automated-tests.
I am using WildFly 8.2 Final is released!
Does anyone know what can it be?

No qualifying bean ... spring-webmvc: bean defined in applicationContext is not visible in ServletContext

I have problems with beans defined in APplicationContext. (May be my problems is understanding of Application~Servlet contexts ?)
So, I define < bean id="messageSource" in :
applicationContext.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.
<!-- // configure manage of transactions using annotations #Transactional // -->
<tx:annotation-driven />
<!-- // SPRING-SECURITY // -->
<import resource="security-servlet.xml" />
<!-- // DB1 - Database Configuration // -->
<context:property-placeholder location="/WEB-INF/spring/db.config/jdbc-db1.properties" />
<import resource="./db.config/DataSource-db1.xml" />
<import resource="./db.config/jpa-config-db1.xml" />
<!-- Auto scan the components -->
<context:annotation-config />
<!-- // common beans for rest & mvc // -->
<context:component-scan base-package="abc.def.data" />
<bean
id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
>
<property
name="basename"
value="validation" />
</bean>
also I have mvc-servlet.xml defines in web.xml as :
<!-- // MVC // -->
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
In my #controller I use bean messageSource such way :
#Controller
#RequestMapping( value = "/admin/su" )
public class AdminSuController {
private final Logger LOG = LoggerFactory.getLogger( getClass() );
.....
#Autowired
private ResourceBundleMessageSource messageSource;
WHEN I define bean in mvc-servlet.xml - no problems
as soon as I move it to (as I understand root context for servletContext) ApplicationContext.xml (I do that to use this beans in REST-servlet.xml and other #controller-s ) I get :
#19:41:26.594 [localhost-startStop-1] ERROR
o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'addressController': Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory .BeanCreationException: Could not
autowire field: private
org.springframework.context.support.ResourceBundleMessageSource
abc.def.rest.controller.AddressController.messageSource; nested
exception is org.sp
ringframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[org.springframework.context.support.ResourceBundleMessageSource]
found for dependency: expected at least 1 bean which qualifies as
autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE ] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
~[spring-context-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)
~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
~[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
[spring-webmvc-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
javax.servlet.GenericServlet.init(GenericServlet.java:158)
[servlet-api.jar:3.0.FR] at
org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
[catalina.jar:7.0.59] at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
[catalina.jar:7.0.59] at
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
[catalina.jar:7.0.59] at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5262)
[catalina.jar:7.0.59] at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5550)
[catalina.jar:7.0.59] at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
[catalina.jar:7.0.59] at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
[catalina.jar:7.0.59] at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
[catalina.jar:7.0.59] at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
[catalina.jar:7.0.59] at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1245)
[catalina.jar:7.0.59] at
org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1895)
[catalina.jar:7.0.59] at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[na:1.7.0] at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
[na:1.7.0] at
java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
[na:1.7.0] at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
[na:1.7.0] at java.lang.Thread.run(Thread.java:722) [na:1.7.0] Caused
by: org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private
org.springframework.context.support.ResourceBundleMessageSource
abc.def.rest.controller.AddressControll er.messageSource; nested
exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[org.springframework.context.support.ResourceBundleMessageSource]
found for dependency: expected at least 1 bean which qualifies as
autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELE ASE] at
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE ] ... 34 common frames
omitted Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
qualifying bean of type
[org.springframework.context.support.ResourceBundleMessageSource]
found for dependency: expected at le ast 1 bean which qualifies as
autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELEASE] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
~[spring-beans-4.1.4.RELEASE.jar:4.1.4.RELE ASE] ... 36 common frames
omitted
Thanks https://stackoverflow.com/users/2843242/oerlien
here is answer Moving messageSource to applicationContext causes the default messageSource not to be visible in dispatcher-servlet context
In your applicationContext.xml:
<bean id="baseMessageSource" class="org.springframework...YourMessageSourceClass">
...
</bean>
In your xxx-servlet.xml:
<bean id="messageSource" parent="baseMessageSource" />

Failed to load ApplicationContext: Spring and junit

Hi I'm trying to test my dao layer with junit, and here is the file structure:
project
*src
main
java
resources
META-INF
persistence.xml
webapp
WEB-INF
applicationContext.xml
web.xml
test
java
resources
testingContext.xml
test-persistence.xml
jdbc.properties
Here is the test cases that I created for my project:
#ContextConfiguration({ "/testingContext.xml" })
#RunWith(SpringJUnit4ClassRunner.class)
public abstract class AbstractDaoForTesting extends AbstractTransactionalJUnit4SpringContextTests {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
#Autowired(required = true)
protected ...
}
And a single test case as follow :
public class MyDaoTest extends AbstractDaoForTesting {
#Test
public void testFind(){}
...
}
Here is the content of testingContext file which is quite similar to my applicationContext
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:jdbc.properties" />
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
/>
<bean id="loadTimeWeaver" class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"
p:showSql="true"
p:databasePlatform="org.eclipse.persistence.platform.database.MySQLPlatform" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="myDataSource"
p:jpaVendorAdapter-ref="jpaVendorAdapter"
p:persistenceXmlLocation="classpath:test-persistence.xml"
/>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:dataSource-ref="tttDataSource"
p:entityManagerFactory-ref="entityManagerFactory"/>
<!-- checks for annotated configured beans -->
<context:annotation-config/>
<!-- Scan for Repository/Service annotations -->
<context:component-scan base-package="com.blah.dao" />
<context:component-scan base-package="com.blah.service" />
<context:component-scan base-package="com.blah.web" />
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven />
</beans>
the build fails because of he test and I get BeanDefinitionStore Exception. I have read many similar items here but I still have the problem. I added #WebAppConfiguration on my test classes but it didn't solve it.
I have to mention that I have used configuration classes to configure Spring MVC as follow
#EnableWebMvc
#Configuration
#ComponentScan("com.blab.web")
public class WebAppConfig extends WebMvcConfigurerAdapter {}
Here is the exception :
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#a0b6fa] to prepare test instance [com.gieman.tttracker.service.CompanyServiceTest#1bc9a8d]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:331)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:159)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.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:597)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
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:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 31 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.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:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 48 more
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.<init>(DefaultServletHandlerConfigurer.java:54)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:346)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf.CGLIB$defaultServletHandlerMapping$26(<generated>)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf$$FastClassBySpringCGLIB$$a898995d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$7245b7bf.defaultServletHandlerMapping(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 49 more
Thanks in advance for your help.
You should check com.gieman.tttracker.service.CompanyServiceTest, the error is :
A ServletContext is required to configure default servlet handling
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:597)
may implements ServletContextAware cause this problem.

Resources