CDI与ejb 3.1,glassfish v3.0.1上的焊接记录器 [英] CDI with ejb 3.1 , weld-logger on glassfish v3.0.1
问题描述
场景:
1)创建maven ear项目,在
内创建war项目2)将beans.xml添加到war项目的WEB-INF /
3)creat simple @Steateless bean
Scenario: 1) create maven ear project, create war project inside 2) add beans.xml to war project`s WEB-INF/ 3) creat simple @Steateless bean
项目 - http://drp.ly/1j5C3t
ejb bean:
@Stateless
@LocalBean
public class TestEjb {
@Inject
Logger log;
public TestEjb() {
}
@Schedule(hour = "*", minute = "*", second = "*/15")
public void print1Partner() {
log.info("Yrjaaaa");
System.out.println("This is test");
}
}
maven pom-xml of war项目:
maven pom-xml of war project :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>Testo</artifactId>
<groupId>ua.co.testo</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Testo-web</artifactId>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ua.eset.oasys</groupId>
<artifactId>utopia</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ua.eset.oasys</groupId>
<artifactId>fenix</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<!-- SL4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
<scope>provided</scope>
</dependency>
<!-- SLF4J JDK14 Binding -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.0</version>
<scope>provided</scope>
</dependency>
<!-- Injectable Weld-Logger -->
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
<scope>provided</scope>
</dependency>
<!--CDI-->
<!-- <dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
<version>1.0-CR4</version>
</dependency>-->
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.2-FCS</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.2-FCS</version>
<scope>provided</scope>
</dependency>
<!--J2EE-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>testo-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<encoding>utf8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
耳朵项目的maven pom.xml:
maven pom.xml of ear project :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>Testo</artifactId>
<groupId>ua.co.testo</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Testo-ear</artifactId>
<packaging>ear</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8
</project.reporting.outputEncoding>
</properties>
<dependencies>
<!--weld-->
<!-- SL4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.0</version>
</dependency>
<!-- SLF4J JDK14 Binding -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.0</version>
</dependency>
<!-- Injectable Weld-Logger -->
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<version>1.0.0-CR2</version>
</dependency>
<!--
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-CR4</version>
</dependency>-->
<dependency>
<groupId>ua.co.testo</groupId>
<artifactId>Testo-web</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>testo</finalName>
<plugins>
<plugin>
<!--<groupId>org.apache.maven.plugins</groupId>-->
<artifactId>maven-ear-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<modules>
<webModule>
<bundleFileName>testo-web.war</bundleFileName>
<groupId>ua.co.testo</groupId>
<artifactId>Testo-web</artifactId>
</webModule>
<!--weld-->
<!-- SL4J API -->
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<!-- SLF4J JDK14 Binding -->
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<!-- Injectable Weld-Logger -->
<jarModule>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-logger</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>
<!--<jarModule>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>-->
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
测试用例1(问题):
部署项目beans.xml给出异常:
Test case 1 ( Problem ): deploying project with beans.xml give exception :
[#| 2010-07-04T19:36:50.003 + 0300 |警告| oracle-glassfish3.0.1 | javax.enterprise.system.container.ejb.com.sun.ejb.containers | _ThreadID = 33; _ThreadName = Thread-1; |在EJB TestEjb方法的
调用期间发生了
系统异常
public void TestEjb.print1Partner()
javax.ejb.EJBException:
javax.ejb.EJBException:
javax.ejb.CreateException:
无法创建无状态EJB
com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:448)
at
com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467)
at
com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1860)
at
com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java) :3962)
at
com.s un.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667)
at
com.sun.ejb.containers.EJBTimerService.access $ 100(EJBTimerService.java:98)
at
com.sun.ejb.containers.EJBTimerService $ TaskExpiredWork.run(EJBTimerService.java:2485)
at
java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:441)
at
java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:303)
at
java.util.concurrent.FutureTask.run(FutureTask.java: 138)
at
java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor $ Worker.run( ThreadPoolExecutor.java:908)
at
java.lang.Thread.run(Thread.java:619)
引起:javax.ejb.EJBException:
javax.ejb。 CreateException:
无法在
com.sun.ejb.containers.StatelessSessionContainer $ SessionContextFactory.create(StatelessS)创建无状态EJB essionContainer.java:720)
at
com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200)
at
com.sun。 ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:443)
... 12更多引起:
javax.ejb.CreateException:
无法在
创建无状态EJB com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:528)
at
com.sun.ejb.containers.StatelessSessionContainer.access $ 000(StatelessSessionContainer.java:90)
at
com.sun.ejb.containers.StatelessSessionContainer $ SessionContextFactory.create(StatelessSessionContainer.java:718)
... 14更多引起:
java.lang.NullPointerException at
java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
at
org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:1171)
at
org.jboss.weld.manager .BeanManagerImpl.getBean(BeanManagerImpl.java:132)
at
org.glassfish.weld.services.JCDIServiceImpl._createJCDIInjectionContext(JCDIServiceImpl.java:145)
at
org.glassfish .weld.services.JCDIServiceImpl.createJCDIInjectionContext(JCDIServiceImpl.java:122)
at
com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1616)
at
com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:469)
... 16更多|#]
[#| 2010-07-04T19:36:50.004 + 0300 | INFO | oracle-glassfish3.0.1 | javax.enterprise.system.container.ejb.com.sun.ejb.containers | _ThreadID = 33; _TreadName = Thread-1; | EJB5119:Expunging
timer
[ '13 @@ 1278255602087 @@ server @@ oasys'
'TimedObject = TestEjb''Application =
testo''BEING_DELIVERED''PERIODIC'
'Container ID = 83771744647118848'
'Sun Jul 04 19:36:45 EEST 2010''0'
'* / 15# *#*#*#*#*#* #null#
null #null#true#print1Partner#
0'] [2]交付失败后|#]
[#|2010-07-04T19:36:50.003+0300|WARNING|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=33;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB TestEjb method public void TestEjb.print1Partner() javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:448) at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467) at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1860) at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3962) at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667) at com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:98) at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2485) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:720) at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200) at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:443) ... 12 more Caused by: javax.ejb.CreateException: Could not create stateless EJB at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:528) at com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:90) at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:718) ... 14 more Caused by: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768) at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:1171) at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:132) at org.glassfish.weld.services.JCDIServiceImpl._createJCDIInjectionContext(JCDIServiceImpl.java:145) at org.glassfish.weld.services.JCDIServiceImpl.createJCDIInjectionContext(JCDIServiceImpl.java:122) at com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1616) at com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:469) ... 16 more |#] [#|2010-07-04T19:36:50.004+0300|INFO|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=33;_ThreadName=Thread-1;|EJB5119:Expunging timer ['13@@1278255602087@@server@@oasys' 'TimedObject = TestEjb' 'Application = testo' 'BEING_DELIVERED' 'PERIODIC' 'Container ID = 83771744647118848' 'Sun Jul 04 19:36:45 EEST 2010' '0' '*/15 # * # * # * # * # * # * # null # null # null # true # print1Partner # 0' ] after [2] failed deliveries|#]
[#| 2010-07-04T19:37:00.000 + 0300 | INFO | oracle-glassfish3.0.1 | javax.enterprise.system.std.com.sun.enterprise.v3.services.impl | _ThreadID = 33; _ThreadName = Thread-1; |这个
是测试|#]
[#|2010-07-04T19:37:00.000+0300|INFO|oracle-glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|This is test|#]
期待结果:
Yrjaaaa
这是测试
结果:
例外
这是测试
案例2:
删除beans.xml
case 2: remove beans.xml
期待结果:
Yrjaaaa
这是测试
结果
Yrjaaaa
这是测试
目标:我想使用ejb焊接(CDI)在耳朵档案馆内的网络项目中,包括其他一些战争& ejb项目,但我不想分开我的网络项目(战争+ ejb)
Goal: I want to use ejb weld(CDI) in web project inside ear archive that include some other war & ejb projects, but i don`t wond to separate my web project (war + ejb )
工具&环境:maven& ejb 3.1&焊接和glassfish 3.0.1
tools & environment : maven & ejb 3.1 & weld & glassfish 3.0.1
Q1:这可能是某种特定的玻璃鱼虫吗?
Q2:可能导致问题的原因是什么?
Q3:这种情况有什么设计吗?
Q1: is this could be some kind of specific glassfish bug ? Q2: what could be a cause of problem? Q3: is there is some design for such case ?
谢谢。
推荐答案
看起来我们可以在glassfish ejb容器的情况下使用ejb中的焊接记录器注入,因为它是ejb容器管理的bean而且它
t见生产者
looks like we cant use Injection of weld logger in ejb in a case of glassfish ejb container because of it is ejb container managed bean and it don
t see producer
目前的设计是将ejb和war模块分开 - 在列表中它为我分叉。
Current design is to separate ejb and war module - at list it forks for me.
这篇关于CDI与ejb 3.1,glassfish v3.0.1上的焊接记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!