我的.ear内有一个.sar,内容如下:
<server xmlns="urn:jboss:service:7.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:service:7.0
http://www.jboss.org/schema/jbossas/jboss-service_7_0.xsd">
<mbean code="com.org.services.listener.MyService"
name="com.org.services.listener:service=MyService">
</mbean>
</server>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.2" bean-discovery-mode="annotated">
<!-- some content -->
</beans>
public interface MyServiceMBean {
public void start();
public void stop();
}
@ApplicationScoped
public class MyService implements MyServiceMBean {
private final CustomScopeTests customScopesThread;
public MyService() {
super();
this.customScopesThread = null;
System.out.println("This gets executed from jboss-service.xml");
}
@Inject
public MyService(final CustomScopeTests customScopesTrhead) {
this.customScopesThread = customScopesTrhead;
System.out.println("This never gets executed");
}
public void start() {
customScopesThread.startThread(); // Null pointer since it was not instantiated via CDI
}
public void stop() {
if(customScopesThread != null)
customScopesThread.stopThread();
}
}
问题:
无论如何,我无法使jboss-service使用CDI来实例化此初始@ApplicationScoped
MyService
,因此,没有任何效果。