Vaadin 7.3.1 + Spring 4.1.0.RELEASE problem

I’m trying to make my Vaadin(7.3.1) application aware about my Spring(4.1.0.RELEASE) application context without any success.

I have the following files:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/spring/application-context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>requestContextFilter</filter-name>
        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
        <init-param>
            <param-name>threadContextInheritable</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>requestContextFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

</web-app>

application-context.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- property-placeholder configuration -->
<context:property-placeholder location="classpath*:*.properties" />

<!-- Turn on AspectJ @Configurable support -->
<context:spring-configured />

<context:component-scan base-package="com.mycompany" />

<!-- Turn on @Autowired, @PostConstruct etc support -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages" />

<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver"
p:defaultLocale="en_US" />

<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>

<bean
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>

</beans>

and my UI

@PreserveOnRefresh
@Configurable(preConstruction = true)
public class ApplicationUI extends UI {

    @Autowired
    private MessageSource messageSource;
    
    private boolean testMode = false;
    
    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = ApplicationUI.class)
    public static class Servlet extends VaadinServlet {

        @Override
        protected void servletInitialized() throws ServletException {
            super.servletInitialized();
            getService().addSessionInitListener(new ValoThemeSessionInitListener());
        }
    }
.....

messageSource property is null… How to correctly wire ApplicationUI.messageSource with messageSource from Sping context ?

Where is the problem is in my code or in approach at all ?

Try making your UI class implement
ApplicationContextAware
interface.

[code]

@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
messageSource = applicationContext;
}
[/code]

omar alles, Implemented… the method setApplicationContext doesn’t invoked

I’ve found that enabling debug logging on the spring packages usually gives some insight.

or

Finally, thanks to this project - http://www.lexaden.com/main/entry/spring_3_1_and_vaadin I have configured Vaadin UI with Spring application context

Tha was not end :slight_smile: I have reimplemented my application one more time based on the AWESOME Vaadin4Spring add-on https://github.com/peholmst/vaadin4spring and Spring Boot

Do you still have that project? the URL is no longer valid.

Thanks!