I am trying to get Spring to initialize a single bean for me. Note that I am not interested in a dispatcher (I think), since I don't care about having the Vaadin components themselves init'd by Spring.
Here is what I have so far:
web.xml:
<web-app
id="WebApp_ID" version="2.4"
xmlns="http://ift.tt/qzwahU"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/qzwahU
http://ift.tt/16hRdKA">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>TAM</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>com.sgss.tam.web.MainUI</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>TAM</servlet-name>
<url-pattern>/tam/*</url-pattern>
</servlet-mapping>
</web-app>
spring-context.xml:
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU" xmlns:context="http://ift.tt/GArMu7"
xmlns:jaxrs="http://ift.tt/1kNxCZA"
xsi:schemaLocation="
http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/GArMu7
http://ift.tt/QEDs1k
http://ift.tt/1kNxCZA
http://ift.tt/1iXPm5B
">
<!-- Turn on AspectJ @Configurable support -->
<context:spring-configured />
<context:component-scan base-package="com.sgss.tam" />
<!-- Turn on @Autowired, @PostConstruct etc support -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean id="envVars" class="com.sgss.tam.service.EnvironmentVars">
<property name="workflowEngineUrl" value="fafafaf"></property>
<property name="userAuthenticationUrl" value="fofofo"></property>
</bean>
</beans>
The point of this exercise is simply to have com.sgss.tam.service.EnvironmentVars configured by Spring. If that can work, then I should be able to access this bean in my UI subclass, by implementing WebApplicationInitializer thusly:
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
final ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
final EnvironmentVars envVars = context.getBean("envVars", EnvironmentVars.class);
}
However...
Instead, when executing the code above in onStartup, here is what actually happens:
2015-02-24 15:53:34.814:INFO:/:main: Spring WebApplicationInitializers detected on classpath: [com.sgss.tam.web.MainUI@30b1a21d]
2015-02-24 15:53:42.706:WARN:oeja.ServletContainerInitializersStarter:main:
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
at com.sgss.tam.web.MainUI.onStartup(MainUI.java:69)
as if I has not defined a listener in web.xml.
If I change the listener-class to something non-existent, then I see an appropriate error message informing me that that class is not found, which demonstrates that this configuration is actually being parsed. So why is there no Spring context?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire