0
我最近開發了一個Glassfish應用程序,開發進行得非常順利,現在用JBoss我正在嘗試做同樣的事情,但由於各種問題如:@EJB工作,但@注入失敗。我還沒有一個花哨的類,我只有一個Singleton Startup類和一個簡單的無狀態類,我注入了,令我驚訝的是注入不起作用。這裏是我的類:JBoss7.1.3:@EJB在@Inject失敗時工作
package com.czetsuya.dropship;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
@Startup
public class StartupListener {
private Logger log = LoggerFactory.getLogger(StartupListener.class);
@EJB
private TestService testService;
public StartupListener() {
}
@PostConstruct
private void init() {
testService.test();
log.debug("startup");
}
}
服務類:
package com.czetsuya.dropship;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless
@LocalBean
public class TestService {
public TestService() {
}
public void test() {
System.out.println("run");
}
}
的另一件事是,如果我注入我的記錄器具有以下生產者也不能正常工作,並拋出:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject private com.czetsuya.dropship.StartupListener.log]
記錄儀生產商:
@Produces
Logger createLogger(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
請注意,我的ejb和war項目中有beans.xml。
我的beans.xml文件:
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/beans_1_0.xsd"></beans>