I am using Spring 3.0.7 and for some reason in our JBOSS web application we cannot get ServletContext in our bean:
@Component("assembler") public class DefaultAssemblerStrategy implements AssemblerStrategy//, ServletContextAware { @Autowired
Note that this is not on the web server itself during the launch of the JUnit test case.
If I try Autwired, I get this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'assembler': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.servlet.ServletContext com.ibm.retail.xc.maestro.web.theme.impl.DefaultAssemblerStrategy.servletCtxt; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [javax.servlet.ServletContext] 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:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean (AbstractAutowireCapableBeanFactory.java:1073)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java∗16)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:455)
And if I implement ServletContextAware , it's just null ...
source share