- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于一些小型 JBoss 企业应用程序的测试,我想使用 JUnit 和 Maven Cargo plugin . (我知道还有 JSFUnit,但首先我想仔细看看 Cargo。)
是否有一个简单的在线示例,我可以将其用作运行 JUnit 测试的引用,该测试使用 Maven Cargo 插件使用 JBoss(4.2 或 5.1)调用 EJB 操作?我找到了一些很好的配置介绍,但我在 EJB 查找中收到错误消息,因此了解应该如何使用它会很有帮助。
下面是使用 InitialContext 的测试代码:
public void testEcho() {
assertEquals("Echo Echo", lookupEchoBeanRemote().Echo("Echo"));
}
private EchoBeanRemote lookupEchoBeanRemote() {
try {
Context c = new InitialContext();
return (EchoBeanRemote) c.lookup("EchoBean/remote");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
这给出了这个错误:
testEcho(de.betabeans.Echo2Test) Time elapsed: 0.885 sec <<< ERROR!
java.lang.reflect.UndeclaredThrowableException
at $Proxy3.Echo(Unknown Source)
at de.betabeans.Echo2Test.testEcho(Echo2Test.java:17)
Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.ejb3.security.client.SecurityActions.createSecurityContext(SecurityActions.java:657)
at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:59)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
at $Proxy4.invoke(Unknown Source)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
... 28 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.jboss.security.SecurityContextFactory.createSecurityContext(SecurityContextFactory.java:117)
at org.jboss.security.SecurityContextFactory.createSecurityContext(SecurityContextFactory.java:76)
at org.jboss.ejb3.security.client.SecurityActions$1.run(SecurityActions.java:662)
... 38 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/security/jacc/PolicyContextException
at java.lang.ClassLoader.defineClass1(Native Method)
如果我使用 EJB 注解
@EJB(beanInterface=EchoBeanRemote.class,mappedName="EchoBean/remote")
private EchoBeanRemote newSessionBean;
public Echo3Test(String testName) {
super(testName);
}
public void testEcho() {
assertEquals("Echo Echo", newSessionBean.Echo("Echo"));
}
测试结果为
testEcho(de.betabeans.Echo3Test) Time elapsed: 0.001 sec <<< ERROR!
java.lang.NullPointerException
at de.betabeans.Echo3Test.testEcho(Echo3Test.java:20)
jndi.properties 位于 EJB jar 根文件夹中并包含以下行:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
### The TimedSocketFactory connection timeout in milliseconds (0 == blocking)
jnp.timeout=0
### The TimedSocketFactory read timeout in milliseconds (0 == blocking)
jnp.sotimeout=0
bean源码是
package de.betabeans;
import javax.ejb.Remote;
@Remote
public interface EchoBeanRemote {
String Echo(final String in);
}
package de.betabeans;
import javax.ejb.Stateless;
@Stateless
public class EchoBean implements EchoBeanRemote {
public String Echo(final String in) {
return in + " " + in;
}
}
我还测试了一个 Web 应用程序,它可以毫无问题地调用 EJB - 两种方式,使用 InitialContext 或注释。我在部署 Web 应用程序时收到的警告是
警告 [MappedReferenceMetaDataResolverDeployer] JBossWebMetaData 中存在未解析的引用:[#web-app:AnnotatedEJBReferenceMetaData{name=de.betabeans.Echo3Servlet/echoBean,ejb-ref-type=null,link=null,ignore-dependecy=false,mapped/jndi-name=EchoBean/remote,resolved-jndi-name=null,beanInterface=interface de.betabeans.EchoBeanRemote}, #web-app:AnnotatedEJBReferenceMetaData{name=NewServlet/newSessionBean,ejb-ref-type=null,link= null,ignore-dependecy=false,mapped/jndi-name=NewSessionBean/remote,resolved-jndi-name=null,beanInterface=接口(interface) de.betabeans.NewSessionBeanRemote}]12:26:11,770 信息
在两个不同的构建系统上使用 JBoss 5.1.0.GA 执行的所有测试。
我现在已经将完整的 Maven 项目上传到 http://www.mikejustin.com/download/JBossSimpleEJBApp-ejb-test.zip
最佳答案
编辑:添加源后
首先 - 我的示例适用于 JBoss 4.2.3.GA 和 Cargo 1.0我对您的代码进行了一些重构:
pom.xml 文件
<groupId>de.betabeans</groupId>
<artifactId>JBossSimpleEJBApp-ejb-test</artifactId>
<packaging>ejb</packaging>
<version>1.0-SNAPSHOT</version>
<name>JBossSimpleEJBApp-ejb JEE5 EJB Test</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb3</artifactId>
<version>4.2.3.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.client</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.3.GA</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>repository.jboss.com</id>
<name>Jboss Repository for Maven</name>
<url>http://repository.jboss.com/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.1</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0</version>
<configuration>
<container>
<containerId>jboss42x</containerId>
<home>${jboss.home}</home>
<append>false</append>
</container>
<configuration>
<type>existing</type>
<home>${jboss.home}/server/default</home>
<properties>
<cargo.jboss.configuration>default</cargo.jboss.configuration>
<cargo.rmi.port>1099</cargo.rmi.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
<wait>false</wait>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>JBossSimpleEJBApp-ejb-test</finalName>
</build>
我在以下部分更改了您的 pom:
我已将资源文件夹移动到测试文件夹
jndi.properties 文件必须由测试(不是 beans)使用,并且可以如下所示或者您拥有:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
不需要其他配置文件(jboss.xml、MANIFEST.MF)。
服务器配置
jboss 4.2.3.GA server 和ejb.jar 文件最大的问题是默认不工作!您可以找到问题和解决方法的描述 here . (这是最难的事情。在 Jboss 5.0 服务器中不存在这个问题,但在 maven-cargo-plugin 中这个容器是实验性的)
就这些
下面我粘贴了一些引用链接,如果你还有问题,我会把我的整个固定项目发给你。
这篇来自 Carlos Sanchez blog 的帖子对您来说非常有用.也许您也可以使用 Selenium 而不是 JSFUnit :)
要复制数据源文件,我使用以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-ds-context</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<outputDirectory>${jboss.deploy-ds.dir}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/webresources/META-INF</directory>
<filtering>true</filtering>
<includes>
<include>context-ds.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
关于maven-2 - 在哪里可以找到用于 EJB 测试的完整 Maven Cargo 插件示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1707740/
我需要审核 ejb bean 的调用。说审计我的意思是将当前登录的用户、方法名称、附加描述等信息写入数据库。我决定使用 CDI 装饰器来做到这一点: @Decorator public class A
当我使用 EJB 3.0 部署 Web 应用程序时,我看到了以下警告: WARNING: jar 'E:\mws\MCDS\portal\portal-web\target\portal-web-1.
我正在学习 EJB,当尝试使用 junit 测试它时,出现以下错误 cd.espoirmur.Ejb.InterfaceEjbLocal_80488159 Jun 03, 2016 10:33:58
是否可以在另一个 EJB 中使用 @EJB?我现在正在尝试这样做,但我的 EJB 最终为空。我将在示例中概述我的问题。 @Stateless @LocalBean @Local(LoginServic
我已通读 article试图理解为什么要在客户端和实体 bean 之间有一个 session bean。是不是因为让客户端直接访问实体bean,就让客户端对数据库一清二楚了? 因此,通过使用中间人(
我们正在尝试在具有两个节点的以域模式运行的 Wildfly 中查找远程 EJB。 设置是这样的: Wildfly 节点 1: 模块 A:EJB 客户端 模块 B:远程 EJB Wildfly 节点 2
我正在使用 Jboss 7,并且有两个单独的部署,它们都包含单例 EJB。 我需要一个 EJB 才能访问另一个 EJB 并能够调用其方法,但是,当应用程序服务器启动并尝试部署它们时,它似乎无法保证哪个
可能最好的方法是手动完成。但是在大型项目中,您需要一些工具来帮助您。正是这个想法促使我搜索了一个工具。 是否有任何 EJB 迁移工具可用于将 EJB 2.0 迁移到 3.x。 最佳答案 它的开发时间很
I am migrating Ejb 2.1 to Ejb 3.1. I changed Java Version from 1.6 to 1.8, and Ejb Version from 2.1
我已经使用 @ActivationConfigProperty 配置了消息目标类型、名称等。在 EJB 3.0 中,但我想配置 MDB使用部署描述符 ( ejb-jar.xml ),就像在 EJB 2
假设我有两个 EJB jar:A.jar 和 B.jar。我可以使用 CDI 将不是 EJB 的实用程序类 Autil 注入(inject) A.jar 中的 POJO 到 B.jar 中的 EJB
我有一个需要配置不同的现有项目。这需要在没有重大代码更改的情况下发生。我实际上希望我只能通过配置以某种方式做到这一点。在过去的 2 到 3 天里,我一直在阅读我能找到的关于这个问题的所有内容。我了解
我有一个非常简单的带有maven的ejb 3.0模块,它只有两个 session bean,一个是无状态的,另一个是单例的...当我尝试在Glassfish 3.0服务器上部署该项目时,我得到了这个异
我们在微服务中看到的是一个孤立的组件,通过协议(protocol)通过网络与该组件的父消费者进行通信。 我们在 EJB 1.0 中看到了非常相似的模式。 我的问题是:微服务架构模式是否类似于 EJB
我在 Java EE6 Singleton Session Bean 中有一个方法,它每 30 秒由 @Schedule(...) 计时器调用。这按预期工作,直到在方法中抛出并捕获异常(异常在 try
我正在 JDeveloper 11.1.1.4 中开发一个 JAX-WS WebService,它应该使用之前部署到 WebLogic 服务器的 JAR 中的 EJB。 WebService项目和EJ
我正在尝试使用 JAX-RS 注释将一些 EJB 公开为 REST Web 服务。当我部署 war WEB-INF/lib 中包含 EJB Jar 的文件到 Wildfly 8,我可以在 Web 管理
我是 EJB 方面的新手,但我已经获得了 EJB 级别的提升。 该层由一个 EJB 组成,它公开可用的操作: @Stateless(name = "myejb") public class Facad
假设我想创建一个我将在未来项目中使用的库,但我还想在该库中包含引用其他 EJB 等的 EJB。该库还将包含简单的 Java 类。最好的方法是什么?在这种情况下如何定义依赖关系?我想我会用注释来定义它们
我想知道是否可以按照这些思路做一些事情: 1)服务器端(EJB类) @Statefull public class SomeEJB implements SomeEJBRemote { @Resour
我是一名优秀的程序员,十分优秀!