gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:37:04 26 4
gpt4 key购买 nike

已更新

我发现了可疑的日志条目:

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(">>mainWindow is null");)

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

我尝试了几种配置变体,例如在 applicationContext 等中。

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

感谢您提前投入的时间和精力。

萨巴

应用程序.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 !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>

最佳答案

为什么使用@Configurable?您的意思是使用@Component 来代替吗?

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

关于Web 应用程序中的 JavaConfig 问题(Vaadin + Spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7535572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com