在 JavaDelegate 中使用远程 EJB 时出错 - Activiti
Error when consuming Remote EJB in JavaDelegate - Activiti
我遇到了以下问题:
我需要使用来自 class 的 EJB Remote,它实现了 Activity 的 JavaDelegate(露天)。
当我的工作流程到达 ServiceTask 时会发生这种情况(我正在使用 "Task Type": ExpressionDelegate 但它也会发生在 "Task Type": Class),此任务使用 FooDelegate在这个 class 中,它包含一个我无法使用的 EJB,当我使用 EJB 时,它总是给我 NullPointerException 错误。
在服务任务的属性中是:
不过也用过"Task Type: Class"
我的HelloWorldBean代码是:
@Stateless
public class DemoImpl implements JavaDelegate {
@EJB(name = "FooServ")
private FooInterface fooServ;
@Override
public void execute(DelegateExecution execute) throws Exception {
System.out.println(">>>> hello world my name is " + fooServ.getNameDefault() + " <<<<");
}
}
在我的文件 "Activiti.cfg.xml" 中有这个:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
...
..
<bean id="HelloWordBean" class="com.development.workflow.HelloWordClass"/>
<jee:remote-slsb id="FooServ" resource-ref="false" business-interface="com.production.FooInterface" jndi-name="java:global/production-ejb/FooServ" />
..
...
</beans>
我还在 jboss-web.xml:
中声明了我的远程 ejb
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
<context-root>/demo</context-root>
<virtual-host>demo-host</virtual-host>
<security-domain>demo-realm</security-domain>
<resource-ref>
<res-ref-name>jdbc/demo</res-ref-name>
<jndi-name>java:/platform/jdbc/demo-flow</jndi-name>
</resource-ref>
<ejb-ref-name>FooServ</ejb-ref-name>
<jndi-name>java:/production/FooServ</jndi-name>
</ejb-ref>
</jboss-web>
如您所见,在两个 xml 文件中声明 FooServ Remote EJB,但我无法使其工作,我总是在使用 Remote EJB 的行中遇到 JavaNullPointerException 错误。
我的 EJB Remote 的代码是:
package com.production;
public interface FooInterface {
String getNameDefault();
}
package com.production.Impl;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Stateless
@Local(FooInterface.class)
public class FooImplement implements FooInterface {
@Override
public String getNameDefault() {
return "I am EJB remote";
}
}
我正在使用 wildfly 10、jee7、activiti 5.2.2。
如何在我的项目中使用该 EJB?提前致谢 :D
非常感谢@Philippe,我实现了一个显式查找(使用 JNDI)并且这对我来说是正确的。我使用的代码是:
public FooService getEJB() {
try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:/production/FooServ");
return (FooService) obj;
} catch (NamingException e) {
e.printStackTrace();
}
}
我遇到了以下问题:
我需要使用来自 class 的 EJB Remote,它实现了 Activity 的 JavaDelegate(露天)。
当我的工作流程到达 ServiceTask 时会发生这种情况(我正在使用 "Task Type": ExpressionDelegate 但它也会发生在 "Task Type": Class),此任务使用 FooDelegate在这个 class 中,它包含一个我无法使用的 EJB,当我使用 EJB 时,它总是给我 NullPointerException 错误。
在服务任务的属性中是:
不过也用过"Task Type: Class"
我的HelloWorldBean代码是:
@Stateless
public class DemoImpl implements JavaDelegate {
@EJB(name = "FooServ")
private FooInterface fooServ;
@Override
public void execute(DelegateExecution execute) throws Exception {
System.out.println(">>>> hello world my name is " + fooServ.getNameDefault() + " <<<<");
}
}
在我的文件 "Activiti.cfg.xml" 中有这个:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
...
..
<bean id="HelloWordBean" class="com.development.workflow.HelloWordClass"/>
<jee:remote-slsb id="FooServ" resource-ref="false" business-interface="com.production.FooInterface" jndi-name="java:global/production-ejb/FooServ" />
..
...
</beans>
我还在 jboss-web.xml:
中声明了我的远程 ejb<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
<context-root>/demo</context-root>
<virtual-host>demo-host</virtual-host>
<security-domain>demo-realm</security-domain>
<resource-ref>
<res-ref-name>jdbc/demo</res-ref-name>
<jndi-name>java:/platform/jdbc/demo-flow</jndi-name>
</resource-ref>
<ejb-ref-name>FooServ</ejb-ref-name>
<jndi-name>java:/production/FooServ</jndi-name>
</ejb-ref>
</jboss-web>
如您所见,在两个 xml 文件中声明 FooServ Remote EJB,但我无法使其工作,我总是在使用 Remote EJB 的行中遇到 JavaNullPointerException 错误。
我的 EJB Remote 的代码是:
package com.production;
public interface FooInterface {
String getNameDefault();
}
package com.production.Impl;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Stateless
@Local(FooInterface.class)
public class FooImplement implements FooInterface {
@Override
public String getNameDefault() {
return "I am EJB remote";
}
}
我正在使用 wildfly 10、jee7、activiti 5.2.2。
如何在我的项目中使用该 EJB?提前致谢 :D
非常感谢@Philippe,我实现了一个显式查找(使用 JNDI)并且这对我来说是正确的。我使用的代码是:
public FooService getEJB() {
try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:/production/FooServ");
return (FooService) obj;
} catch (NamingException e) {
e.printStackTrace();
}
}