0

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>
cscsaba
  • 1,279
  • 3
  • 20
  • 31

2 Answers2

2

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.

Chris Beams
  • 1,473
  • 10
  • 13
  • Hello, **1.** I followed an tutorial which makes the Vaadin App class managed be Spring Container. So the App class was in focus an has important role to couple Vaadin and Spring. And this class was annotated by atConfigurable thats why I was not dare enough to remove :) **2.** I made a test project according to spring doc [link](http://goo.gl/qlpQf) and there is no class annotated by atComponent, although component scan is used there. Plus, the test project works without atComponent annotation [pic](http://img684.imageshack.us/img684/4163/image000m.png). – cscsaba Sep 27 '11 at 18:29
  • Although, after several attempt I tried to use atComponent annotation on the classes must be wired. But It did not work. Obviously I made something wrongly. I take your words and thanks for your advice. – cscsaba Sep 27 '11 at 18:38
  • (One of my class from the javaconfig test case [link](http://test-workbench.googlecode.com/svn/projects/vs2/tags/0/src/main/java/com/mycompany/MavenVaadinSpring/service/UserManagerImpl.java)) – cscsaba Sep 27 '11 at 18:42
1

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.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
TiC
  • 21
  • 2
  • Hello Wladimir, sorry for the late reply, but as i know component-scan is enough to Autowire the Components. But I think the real problem is the wrong settings of web.xml where org.springframework.web.servlet.DispatcherServlet can handle contextClass, contextConfigLocation params [**see**](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java). In my case the (see above the snippet of web.xml) com.vaadin.terminal.gwt.server.ApplicationServlet cant use them. – cscsaba Oct 06 '11 at 22:44
  • Hello Wladimir, In spite of my previous opinion is needed, sorry really.Im going to check skelton what you mentioned. Thanks for your effort, really. – cscsaba Oct 14 '11 at 18:41