我在使用SpringBeanAutowiringInterceptor(我正在使用JDK 1.7.0_51和Weblogic12)時收到調用EJB的異常。如果我在EJB中使用SpringBeanAutowiringInterceptor獲取EJB異常
像往常一樣,當我得到這樣的異常,我嘗試創建一個示例應用程序,看看我的應用程序中的任何現有代碼可能有衝突庫。只是爲了從我的主要應用程序隔離它。
所以我來到這裏:
我有一個EJB定義爲(不是我評論@Interceptors(SpringBeanAutowiringInterceptor.class)
package my.company.impl;
import my.company.client.remote.CalculatorRemote;
import org.springframework.stereotype.Component;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless(mappedName = "ejb/MyCalcuatorEJB")
@Remote(CalculatorRemote.class)
//@Interceptors(SpringBeanAutowiringInterceptor.class)
@Component
public class CalculatorEJB implements CalculatorRemote {
private static final long serialVersionUID = 1L;
@Override
public int add(final int a, final int b) {
return a+b;
}
}
而且一個Maven POM
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>my.company</groupId>
<artifactId>my-test-ejb-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<properties>
<cobertura-maven-plugin-ver>2.6</cobertura-maven-plugin-ver>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.2</ejbVersion>
<generateClient>true</generateClient>
<!-- Ensure the a thin EJB-client. -->
<clientIncludes>
<clientInclude>my/company/client/remote/**</clientInclude>
</clientIncludes>
</configuration>
<executions>
<execution>
<id>make-an-ejb</id>
<phase>package</phase>
<goals>
<goal>ejb</goal>
</goals>
<configuration>
<classifier>ejb</classifier>
</configuration>
</execution>
</executions>
</plugin>
<!-- This needs to be removed in real life scenario-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura-maven-plugin-ver}</version>
<configuration>
<check>
<haltOnFailure>true</haltOnFailure>
<totalLineRate>0</totalLineRate>
</check>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<!--No interceptor annotation add yet this will be added later-->
<!-- <dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<scope>provided</scope>
<version>1.2</version>
</dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.5.RELEASE</version>
</dependency>
</dependencies>
</project>
我EAR部署到WebLogic和從IntelliJ我有一個測試類如下
import my.company.client.remote.CalculatorRemote;
import javax.naming.Context;
import javax.naming.NamingException;
import java.util.Hashtable;
public class TestClient {
public static void main(String[] args) {
try {
testUsingJavaSe();
} catch (final Exception ex) {
ex.printStackTrace();
}
}
private static void testUsingJavaSe() throws NamingException {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("java.naming.provider.url", "t3://127.0.0.1:7002");
System.out.println("creating context");
Context ic = new weblogic.jndi.WLInitialContextFactory().getInitialContext(env);
System.out.println("looking up object");
Object object = ic.lookup("ejb/MyCalcuatorEJB#my.company.client.remote.CalculatorRemote");
CalculatorRemote remote = (CalculatorRemote) object;
System.out.println(remote);
System.out.println("invoking ejb");
int result = remote.add(1, 2);
System.out.println("result: " + result);
}
}
現在所有這些工作,當我運行測試類時,我可以看到3被打印到控制檯窗口。
在我的應用程序中,我需要額外的bean在我的EJB中。由於我使用彈簧,我想使用@Autowired
。根據我的理解,我需要刪除@Component
註釋並將其替換爲@Interceptors(SpringBeanAutowiringInterceptor.class)
。
但是爲了使用它,我取消以下依賴性在我的POM
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<scope>provided</scope>
<version>1.2</version>
</dependency>
這讓我導入@Interceptors(SpringBeanAutowiringInterceptor.class)
。
這將允許我啓動可以掃描類和注入bean的Spring Context。
我也有一個beanRefContext.xml,用來啓動我的spring上下文。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="calculatorService" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="classpath*:applicationContext.xml"/>
</bean>
</beans>
指向空applicaitonContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
</beans>
我沒有任何自動裝配還...只是想測試線路和相關工作。
但如果我現在再運行它,我得到以下錯誤
> "C:\Program Files\Java\jdk1.7.0_51\bin\java" -Didea.launcher.port=7539
> "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ
> IDEA 14.0.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\charsets.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\deploy.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\javaws.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\jce.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\jfr.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\jfxrt.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\jsse.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\management-agent.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\plugin.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\resources.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\rt.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\access-bridge-64.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\dnsns.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\jaccess.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\localedata.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\sunec.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\sunjce_provider.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\sunmscapi.jar;C:\Program
> Files\Java\jdk1.7.0_51\jre\lib\ext\zipfs.jar;D:\git\devrepos\dcs\dcs-commons\my-test-ejb-service\testclient\target\classes;D:\git\devrepos\dcs\dcs-commons\my-test-ejb-service\core\target\classes;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-core\4.0.5.RELEASE\spring-core-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-context\4.0.5.RELEASE\spring-context-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-aop\4.0.5.RELEASE\spring-aop-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-beans\4.0.5.RELEASE\spring-beans-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-expression\4.0.5.RELEASE\spring-expression-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\org\springframework\spring-context-support\4.0.5.RELEASE\spring-context-support-4.0.5.RELEASE.jar;D:\Development\Maven\Maven_Repo_Local_DCS\javax\ejb\ejb\3.0\ejb-3.0.jar;D:\Development\Maven\Maven_Repo_Local_DCS\com\oracle\middleware\wlthint3client\12.1.2.0.0\wlthint3client-12.1.2.0.0.jar;C:\Program
> Files (x86)\JetBrains\IntelliJ IDEA 14.0.1\lib\idea_rt.jar"
> com.intellij.rt.execution.application.AppMain TestClient creating
> context looking up object
> ClusterableRemoteRef(-4386785499045922938S:127.0.0.1:[7002,7002,-1,-1,-1,-1,-1]:jDomain:Server7002
> [-4386785499045922938S:127.0.0.1:[7002,7002,-1,-1,-1,-1,-1]:jDomain:Server7002/307])/307
> invoking ejb javax.ejb.EJBException: Problem finding error class;
> nested exception is: java.lang.ClassNotFoundException: Failed to
> load class com.oracle.pitchfork.interfaces.LifecycleCallbackException;
> nested exception is: java.lang.ClassNotFoundException: Failed to load
> class com.oracle.pitchfork.interfaces.LifecycleCallbackException
> java.lang.ClassNotFoundException: Failed to load class
> com.oracle.pitchfork.interfaces.LifecycleCallbackException at
> weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:208)
> at
> weblogic.rmi.utils.WLRMIClassLoaderDelegate.loadClass(WLRMIClassLoaderDelegate.java:135)
> at weblogic.rmi.utils.Utilities.loadClass(Utilities.java:306) at
> weblogic.rjvm.MsgAbbrevInputStream.resolveClass(MsgAbbrevInputStream.java:439)
> at
> weblogic.utils.io.ChunkedObjectInputStream$NestedObjectInputStream.resolveClass(ChunkedObjectInputStream.java:268)
> at
> java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)
> at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
> at
> java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1990)
> at
> java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1915)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1798)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
> at
> weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:208)
> at
> weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:602)
> at weblogic.rjvm.ResponseImpl.getThrowable(ResponseImpl.java:200) at
> weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:248) at
> weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:466)
> at
> weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:274)
> at
> my.company.impl.CalculatorEJB_wo0f1c_CalculatorRemoteImpl_12120_WLStub.add(Unknown
> Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606) at
> weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:84)
> at com.sun.proxy.$Proxy0.add(Unknown Source) at
> TestClient.testUsingJavaSe(TestClient.java:29) at
> TestClient.main(TestClient.java:11) at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606) at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
> javax.ejb.EJBException: Problem finding error class; nested exception
> is: java.lang.ClassNotFoundException: Failed to load class
> com.oracle.pitchfork.interfaces.LifecycleCallbackException; nested
> exception is: java.lang.ClassNotFoundException: Failed to load class
> com.oracle.pitchfork.interfaces.LifecycleCallbackException at
> weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:117)
> at
> weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:92)
> at com.sun.proxy.$Proxy0.add(Unknown Source) at
> TestClient.testUsingJavaSe(TestClient.java:29) at
> TestClient.main(TestClient.java:11) at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606) at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
>
> Process finished with exit code 0
我不知道我在做什麼錯在這裏。任何想法?
'java.lang.ClassNotFoundException:無法加載類 > com.oracle.pitchfork.interfaces.LifecycleCallbackException'這表示jar文件丟失!我想 – VinayVeluri