web应用程序中的JavaConfig问题(Vaadin+;Spring)

web应用程序中的JavaConfig问题(Vaadin+;Spring),java,web-applications,configuration,aop,load-time-weaving,Java,Web Applications,Configuration,Aop,Load Time Weaving,更新 我发现一个可疑的日志条目: 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.projectna

更新

我发现一个可疑的日志条目:

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.
/更新

我正在开发一个Vaadin+Spring应用程序,我希望使用JavaConfig

根据一些教程,我分别构建了它们,但是当我合并它们时,我得到了以下结果(请参阅第一个codesnipet App.java-logger.info(“>>主窗口为空”);)

我尝试了几种不同的配置,例如applicationContext等

所以我的问题是:我怎样才能找出真正的问题

提前感谢您的时间和努力

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

。。。
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
com.mycompany.projectname.config.AppConfig
...
Vaadin应用程序Servlet
com.vaadin.terminal.gwt.server.ApplicationServlet
要启动的Vaadin应用程序类
应用
com.mycompany.projectname.App
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
com.mycompany.projectname.config.AppConfig

为什么要使用@Configurable?您的意思是使用@Component吗


@可配置通常用于非Spring管理对象的域对象(aka实体),以允许它们从Spring容器接收依赖项注入。这似乎不是你的目标。您可能应该简单地将“App”类连接为另一个@Bean方法,或者用@Component标记它,并通过组件扫描(例如用@ComponentScan)将其提取出来。有关这些注释的更多信息,请查看相关的Javadoc和参考文档。

为什么要使用@Configurable?您的意思是使用@Component吗


@可配置通常用于非Spring管理对象的域对象(aka实体),以允许它们从Spring容器接收依赖项注入。这似乎不是你的目标。您可能应该简单地将“App”类连接为另一个@Bean方法,或者用@Component标记它,并通过组件扫描(例如用@ComponentScan)将其提取出来。有关这些注释的更多信息,请查看相关的Javadoc和参考文档。

如果未启用注释,它们将无法工作

您的项目spring上下文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" />


更新:查看。

如果未启用注释,则注释将无法工作

您的项目spring上下文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" />


更新:看。

你好,1。我遵循了一个使Vaadin应用程序类成为Spring容器的教程。因此,应用程序类在Vaadin和Spring之间扮演着重要的角色。而这个类是由atz注释的,这就是为什么我不敢删除:)2。我根据SpringDoc做了一个测试项目,虽然使用了组件扫描,但atComponent并没有注释任何类。另外,测试项目在没有atComponent注释的情况下也可以工作。不过,经过几次尝试后,我尝试在类上使用atComponent注释,但必须连接。但它没有起作用。很明显我做错了什么。我相信你的话,谢谢你的建议。(我的一个班级来自javaconfig测试用例)你好,1。我遵循了一个使Vaadin应用程序类成为Spring容器的教程。因此,应用程序类在Vaadin和Spring之间扮演着重要的角色。而这个类是由atz注释的,这就是为什么我不敢删除:)2。我根据SpringDoc做了一个测试项目,虽然使用了组件扫描,但atComponent并没有注释任何类。另外,测试项目在没有atComponent注释的情况下也可以工作。不过,经过几次尝试后,我尝试在类上使用atComponent注释,但必须连接。但它没有起作用。很明显我做错了什么。我相信你的话,感谢你的建议。(我的一个班级来自javaconfig测试用例)你好,Wladimir,很抱歉回复太晚,但我知道组件扫描足以自动连接组件。但我认为真正的问题是web.xml的错误设置,org.springframework.web.servlet.DispatcherServlet可以处理contextClass、contextConfigLocation参数。在我的情况下(见上面的web.xml片段)com.vaadin.terminal.gwt.server.ApplicationServlet无法使用它们。您好,Wladimir,尽管我之前的意见是必要的,但真的很抱歉。我将检查skelton您提到的内容。谢谢你的努力,真的。你好,瓦拉迪米尔,很抱歉回复晚了,但据我所知,组件扫描足以自动连接组件。但我认为真正的问题是web.xml的错误设置,org.springframework.web.servlet.DispatcherServlet可以处理contextClass、contextConfigLocation参数。在我的情况下(见上面的web.xml片段)com.vaadin.terminal.gwt.server.ApplicationServlet无法使用它们。您好,Wladimir,尽管我之前的意见是必要的,但真的很抱歉。我将检查skelton您提到的内容。谢谢你的努力,真的。
<!-- 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" />