0
我有這個類在java端創建一個套接字。問題是,它拋出一個java.lang.IllegalArgumentException: No bean found for class com.production.workflow.process.approval.ApprovalSocketHandler
儘管@Component和@Bean沒有找到類的bean
package com.production;
@WebListener
public class SocketInitializer implements ServletContextListener {
public static App app;
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
AutowireCapableBeanFactory beanFactory = ApplicationContextProvider.getApplicationContext().getAutowireCapableBeanFactory();
app = new App(new Options().url("/socket/workstation/approval").packageOf(this), new AtmosphereModule(servletContextEvent.getServletContext()), new SpringModule(beanFactory));
app.bean(ApprovalSocketHandler.class).init();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}
的包,這個類中,確實正在通過我的配置掃描。我懷疑這個Listener正在被初始化,該配置還沒有被掃描。
@Configuration
@ComponentScan(basePackages = {
"com.production"
})
@PropertySource(value= {
"classpath:/application.properties",
"classpath:/environment-${MY_ENVIRONMENT}.properties"
})
@EnableJpaRepositories("com.production.repository")
@EnableTransactionManagement
public class Config {
@Value("${db.url}")
String PROPERTY_DATABASE_URL;
@Value("${db.user}")
String PROPERTY_DATABASE_USER;
@Value("${db.password}")
String PROPERTY_DATABASE_PASSWORD;
@Value("${persistenceUnit.default}")
String PROPERTY_DEFAULT_PERSISTENCE_UNIT;
@Value("${hibernate.dialect}")
String PROPERTY_HIBERNATE_DIALECT;
@Value("${hibernate.format_sql}")
String PROPERTY_HIBERNATE_FORMAT_SQL;
@Value("${hibernate.show_sql}")
String PROPERTY_HIBERNATE_SHOW_SQL;
@Value("${entitymanager.packages.to.scan}")
String PROPERTY_ENTITYMANAGER_PACKAGES_TO_SCAN;
@Bean
public App app() {
return SocketInitializer.app;
}
爲了確保在ServletContextListener執行期間這個類是一個bean,我需要做些什麼?
'ServletContextListener'由Servlet容器加載並註冊。 – 2013-04-29 13:45:50
@SotiriosDelimanolis - 在這種情況下,這有什麼意義? – Webnet 2013-04-29 13:49:49
Servlet容器在Spring之前處理事物,所以bean將不會在'contextInitialized'處獲得。儘管如此,我還沒有解決方案。 – 2013-04-29 13:55:35