Question

UPDATED

I found an suspicious log entry:

org.springframework.beans.factory.wiring.BeanConfigurerSupport:

BeanFactory has not been set on BeanConfigurerSupport: Make sure this configurer runs  in a Spring container. 
Unable to configure bean of type [com.mycompany.projectname.App]. Proceeding without injection.

/UPDATED

I'm working on an Vaadin + Spring application and I wish to use JavaConfig.

According to some tutorial I built them up separately, but when I merge them I got the following (see the first codesnipet App.java - logger.info(">>mainWindow is null");)

app postconstruct --------- 
mainWindow is null

I tried several variation of configs for example in applicationContext and so forth.

So my question is: how can I find out real problem ?

Thanks for your time and effort in advance.

Csaba

App.java

@Configurable
public class App extends Application
{
    public MainWindow mainWindow;    
    public MainWindow getMainWindow(...
    public void setMainWindow(Main....


    @PostConstruct
    public void init()
    {
        logger.info(">>app postconstruct --------- ");
        if(mainWindow==null) logger.info(">>mainWindow is null");
        else logger.info(">>mainWindow is not null");
    }

AppConfig.java

    @Configuration
    public class AppConfig {
    ...
    @Bean
    public MainWindow mainWindow(){
            return new MainWindow();
    }
    ....    
    }

web.xml based on this !tutorial link!

...
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.mycompany.projectname.config.AppConfig</param-value>
</context-param>  
...

<servlet>
    <servlet-name>Vaadin Application Servlet</servlet-name>
    <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>

    <init-param>
    <description>Vaadin application class to start</description>
    <param-name>application</param-name>
    <param-value>com.mycompany.projectname.App</param-value>
    </init-param>

    <init-param>
    <param-name>contextClass</param-name>
    <param-value>
    org.springframework.web.context.support.AnnotationConfigWebApplicationContext
    </param-value>
    </init-param>

    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.mycompany.projectname.config.AppConfig</param-value>
    </init-param>    
</servlet>
Était-ce utile?

La solution

Why are you using @Configurable? Do you mean to be using @Component instead?

@Configurable is typically used on domain objects (aka entities) that are not otherwise Spring-managed objects to allow them to receive dependency injection from the Spring container. This does not appear to be your goal. You should probably simply be wiring up your "App" class as another @Bean method, or otherwise marking it with @Component and picking it up via component-scanning (e.g. with @ComponentScan). Check out the related Javadoc and reference documentation for these annotations for more info.

Autres conseils

Your annotations will not work if you didn't enabled them.

Do you have the following in your project spring context xml ?

<!-- Activate Spring annotation support -->
<context:spring-configured/>

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

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="com.tc.poc.vaddinspring" />

Update: Look at this skeleton.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top