У меня есть .sar внутри моего .ear со следующим:
- src / main / resources / META-INF / jboss-service.xml :
<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>
- src / main / resources / META-INF / beans.xml :
<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
, и поэтому ничего не работает.