我的网络服务存在问题。它抛出异常如下:
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext-datasource.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:389)
at hk.com.xxx.util.ServiceLocator.getApplicationContext(ServiceLocator.java:25)
我有以下代码显示问题:
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.context.ApplicationContext;
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
public class ServiceLocator {
private static ApplicationContext applicationContext;
protected ServiceLocator() {
}
public static ApplicationContext getApplicationContext() {
if (applicationContext == null) {
BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance("applicationContext.xml");
BeanFactoryReference bfr = locator.useBeanFactory("applicationContext");
BeanFactory factory = bfr.getFactory();
applicationContext = (ApplicationContext) factory;
}
return applicationContext;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="applicationContext"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>ApplicationContext-log4j.xml</value>
<value>ApplicationContext-datasource.xml</value>
</list>
</constructor-arg>
</bean>
</beans>
ApplicationContext-datasource.xml - &gt;提取一个有问题的部分
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="AS400ABC"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2400Dialect</prop>
<prop key="hibernate.connection.autocommit">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>hk/com/xxx/bls/dao/CategoryBean.hbm.xml</value>
<value>hk/com/xxx/bls/dao/CustomerBillBean.hbm.xml</value>
<value>hk/com/xxx/bls/dao/MerchantBean.hbm.xml</value>
<value>hk/com/xxx/bls/dao/MerchantBillBean.hbm.xml</value>
<value>hk/com/xxx/bls/dao/PaymentBean.hbm.xml</value>
</list>
</property>
</bean>
然后我在网上google并发现我需要在链接I have trouble setting up spring hibernate application-context.xml中提到的lib中为JDBC 4.1添加Apache Commons Pool 2.4.2和Apache Commons DBCP 2.1.1。
我不确定上述是否正确。如果是,那么现在我在 weblogic集群中部署WAR时遇到了另一个问题。它显示以下错误:java.lang.ClassCastException: net.sf.cglib.proxy.Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72 cannot be cast to net.sf.cglib.core.KeyFactory
。
在我的lib中,它有asm.jar和cglib.jar,如链接http://forum.spring.io/forum/spring-projects/web/flex/65337-an-strange-error-with-net-sf-cglib-core-keyfactory中所述。
我该怎么办? 我在weblogic服务器12.2.1.3上使用JDK7