2017-09-14 9 views
0

Wildfly-swarm을 실험하는 과정에서 나는 콩 주입에 관한 이상한 상황에 처했습니다. 나는 전쟁의 전개에 직접 항아리에이 번들 경우 예상대로Wildfly와 Wildfly - 전쟁 배포 대 커스텀 모듈에서 CDI beans 주입하기

@ApplicationScoped 
public class FooServiceImpl implements FooService { 
    Foo delegate; 
    @PostConstruct public void init() { 
     delegate = .....; 
    } 

    public Foo getFoo() { 
     return delegate; 
    } 
} 

는, 모든 것이 잘 작동하고 :

내가

매우 간단한 콩이 다소 이런 있습니다. 그러나 응용 프로그램과 완전히 분리되도록이 구현의 내부 부품이 필요합니다. 왜 서비스 API 및 해당 구현을 별도의 jboss 모듈에 패키지화 했습니까?

이 모듈은 swarm uberJar에 추가되며 내 응용 프로그램은 MANIFEST 종속성 항목을 통해 해당 모듈에 종속됩니다. 이제는 모든 것이 정상적으로 작동하는 것처럼 보입니다. FooService 빈은 애플리케이션 서블릿/휴지 리소스에 주입되지만 init() 메소드는 호출되지 않습니다.

여기에 무슨 일이 일어나는지 알 수 없습니다. 빈 확인 프로세스가 @ApplicationScope 주석을 인식하지 못하는 것과 같습니다. 거기에 두 개의 다른 클래스 로더가있을 수 있습니까?

UPDATE

나는 추적 활성화 및 용접 즉 생성되는 프록시에 LifecycleMixin.lifecycle_mixin_$$_postConstruct()을 추가 ApplicationScoped로 FooImpl 클래스를 치료하는 것처럼 내게는 보인다 :

2017-09-14 23:11:34,315 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001538: Created context instance for bean Managed Bean [class com.xxx.FooImpl] with qualifiers [@Any @Default] identified as WELD%ManagedBean%test.war|test.war.external.file:/tmp/nestedjarloader2449602760983533131.tmp/META-INF/beans.xml|com.xxx.FooImpl|null|false 
2017-09-14 23:11:34,315 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001542: Retrieving/generating proxy class com.xxx.FooImpl$Proxy$_$$_WeldClientProxy 
2017-09-14 23:11:34,315 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public void com.xxx.FooImpl.registerMessageHandler(com.xxx.MessageHandler) 
2017-09-14 23:11:34,315 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public void com.xxx.FooImpl.registerListeners(java.util.EventListener[]) 
2017-09-14 23:11:34,316 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public void com.xxx.FooImpl.send(com.xxx.MessageHandler,com.xxx.Message) throws java.io.IOException 
2017-09-14 23:11:34,316 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public void com.xxx.FooImpl.init() 
2017-09-14 23:11:34,316 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public java.lang.String java.lang.Object.toString() 
2017-09-14 23:11:34,316 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public abstract void org.jboss.weld.interceptor.proxy.LifecycleMixin.lifecycle_mixin_$$_postConstruct() 
2017-09-14 23:11:34,316 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001541: Adding method to proxy: public abstract void org.jboss.weld.interceptor.proxy.LifecycleMixin.lifecycle_mixin_$$_preDestroy() 
2017-09-14 23:11:34,317 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001543: Created Proxy class of type class com.xxx.FooImpl$Proxy$_$$_WeldClientProxy supporting interfaces [interface com.xxx.FooService, interface java.io.Serializable, interface org.jboss.weld.interceptor.proxy.LifecycleMixin, interface org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy, interface org.jboss.weld.bean.proxy.ProxyObject] 
2017-09-14 23:11:34,317 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001506: Created new client proxy of type class com.xxx.FooImpl$Proxy$_$$_WeldClientProxy for bean Managed Bean [class com.xxx.FooImpl] with qualifiers [@Any @Default] with ID WELD%ManagedBean%test.war|test.war.external.file:/tmp/nestedjarloader2449602760983533131.tmp/META-INF/beans.xml|com.xxx.FooImpl|null|false 
2017-09-14 23:11:34,318 TRACE [org.jboss.weld.Bean] (ServerService Thread Pool -- 12) WELD-001507: Located client proxy of type class com.xxx.FooImpl$Proxy$_$$_WeldClientProxy for bean Managed Bean [class com.xxx.FooImpl] with qualifiers [@Any @Default] 

PostConstruct의 요격 ISN을 왜 호출 된 - 왜? 신비가 깊어집니다! 2

업데이트 제이보스 바닐라에서이를 테스트 및 동작은 빈이 모듈에있는 경우 호출되지 동일 @PostConstruct 방법이다.

+0

API와 Impl이 별도의 JBoss 모듈에 있다면, 그들은 실제로 별도의 클래스 로더에 있습니다. MANIFEST의 impl에 대한 module.xml이 WAR 클래스 로더로 "가져와야"함을 식별합니까? – Ken

+0

@Ken 아니,하지만해야합니까? 내 말은, 자체 클래스 로더에 impl을 원한다는 것입니다. ApplicationScoped는 오직 하나의 클래스 로더에서만 제공되어야합니다. –

답변