myeclipse8+struts2.1+spring2.5+hibernate3.2+weblogic10配置二级缓存时提示错误

弄了两天的二级缓存,一直没有弄好,网上找了很多资料都没能弄好,望各位帮帮忙。
但是工程一样能插入、删除、查询数据。
下面是部分代码,
工程在weblogic部署时和weblogic启动时提示有错误。
weblogic部署工程提示:
java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.()V from class org.hibernate.cache.EhCacheProvider

weblogic服务器启动时提示:
2010-02-03 23:00:43,015 ERROR (org.springframework.web.context.ContextLoader:215) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [
/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access method
net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.ja
va:1338)
---------------------

-------------------------------------------
applicationContext.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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

	<bean id="dataSourcejndioracle" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>orcl/jndn</value>
		</property>
		<property name="resourceRef">
			<value>false</value>
		</property>
		<property name="jndiEnvironment">
			<props>
				<prop key="java.naming.provider.url">t3://localhost:7001</prop>
				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
			</props>
		</property>
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSourcejndioracle" />
		<property name="mappingDirectoryLocations">
			<list>
				<value>classpath:com/wysx/vo</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<!--
					org.hibernate.dialect.MySQLDialect
					org.hibernate.dialect.OracleDialect
				-->
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.connection.release_mode">auto</prop>
				<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
				<prop key="connection.provider_class">org.hibernate.connection.DatasourceConnectionProvider
				</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
				<prop key="hibernate.jdbc.batch_size">20</prop>
				<prop key="hibernate.jdbc.fetch_size">30</prop>
				<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="net.sf.ehcache.configurationResourceName">
					classpath:ehcache.xml
				</prop>
			</props>
		</property>

	</bean>

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>


	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>

	<bean
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>serviceImp</value>
				<value>serviceStuImp</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
	</bean>

	<bean id="DaoImp" class="com.wysx.test.dao.daoImp.DaoImp">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="serviceImp" class="com.wysx.test.service.ServiceImp">
		<property name="daoImp" ref="DaoImp"></property>
	</bean>

	<bean id="DaoStuImp" class="com.wysx.test.dao.daoImp.CacheStudentDaoImp">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="serviceStuImp" class="com.wysx.test.service.imp.CacheStudentImp">
		<property name="cacheStudentDao" ref="DaoStuImp"></property>
	</bean>
</beans>



-----------------------------

ehcache.xml
默认配置
       
    <defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="true"
        />
----------------------------------
weblogic部署工程
weblogic提示:
  java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.()V from class org.hibernate.cache.EhCacheProvider 
  执行此操作时遇到错误。 

myeclipse8+struts2.1+spring2.5+hibernate3.2+weblogic10配置二级缓存时提示错误_第1张图片

-------------------------------------
工程中用到的jar包

myeclipse8+struts2.1+spring2.5+hibernate3.2+weblogic10配置二级缓存时提示错误_第2张图片

-------------------------------------
控制台提示错误信息
2010-02-03 23:00:42,968  INFO (org.hibernate.cfg.SettingsFactory:313) - Named query checking : enabled
2010-02-03 23:00:43,000  INFO (org.hibernate.impl.SessionFactoryImpl:161) - building session factory
2010-02-03 23:00:43,015  INFO (org.springframework.beans.factory.support.DefaultListableBeanFactory:421) - Destroying singletons in org.spri
ngframework.beans.factory.support.DefaultListableBeanFactory@631b3b: defining beans [dataSourcejndioracle,sessionFactory,transactionManager,
transactionInterceptor,org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator#0,DaoStuImp,serviceStuImp]; root of factory hier
archy
2010-02-03 23:00:43,015 ERROR (org.springframework.web.context.ContextLoader:215) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [
/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access method
 net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.ja
va:1338)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java
:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:3
80)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423
)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:72
8)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
        at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:458)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
        at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:168)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1744)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2909)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:973)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:361)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
        at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:117)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
        at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:26)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:635)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212)
        at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:154)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:566)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:136)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:104)
        at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:139)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:320)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:816)
        at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1223)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:434)
        at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:161)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeli
verer.java:181)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.
java:12)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:
67)
        at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:464)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
Caused by: java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCache
Provider
        at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory
.java:1369)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.ja
va:1335)
        ... 52 more
<2010-2-3 下午11时00分43秒 CST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener f
ailed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext res
ource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access
 method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [
/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalAccessError: tried to access method
 net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.ja
va:1338)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java
:473)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:3
80)
        Truncated. see log file for complete stacktrace
java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
        Truncated. see log file for complete stacktrace
>
<2010-2-3 下午11时00分43秒 CST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1265209238
671' for task '0'. Error is: 'weblogic.application.ModuleException: '
weblogic.application.ModuleException:
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:975)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:361)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
        Truncated. see log file for complete stacktrace
java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
        Truncated. see log file for complete stacktrace
>
<2010-2-3 下午11时00分43秒 CST> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 7 task for the appl
ication 'WebRoot'.>
<2010-2-3 下午11时00分43秒 CST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating start task for application 'WebRo
ot'.>
<2010-2-3 下午11时00分43秒 CST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException:
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:975)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:361)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:204)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:26)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:60)
        Truncated. see log file for complete stacktrace
java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
        at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:183)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:814)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:732)
        Truncated. see log file for complete stacktrace
>


myeclipse8+struts2.1+spring2.5+hibernate3.2+weblogic10配置二级缓存时提示错误_第3张图片
-------------------------------------

junit测试
package com.junit;

import java.sql.Connection;
import java.util.List;

import javax.sql.DataSource;

import junit.framework.TestCase;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.opensymphony.xwork2.interceptor.annotations.Before;
import com.wysx.test.service.CacheStudentService;
import com.wysx.test.service.ServiceImp;
import com.wysx.vo.CacheStudent;
import com.wysx.vo.Student;

public class Junit_test extends TestCase {
	ApplicationContext context;

	@Before
	public void setUp() throws Exception {
		context = new FileSystemXmlApplicationContext(
				"WebRoot/WEB-INF/applicationContext.xml");
	}

	// @Test
	public void test() throws Exception {
		DataSource ds = (DataSource) context.getBean("dataSourcejndioracle");
		Connection con = ds.getConnection();
		//
		try {
			indata();

		} catch (Exception e) {
			System.out.println(e.toString());
		}
		con.close();
	}

	public void indata() throws Exception {
		//插入新的数据
//		ServiceImp si = (ServiceImp) context.getBean("serviceImp");
//		for(int i=0;i<10000;i++){
//			Student st = new Student();
//			st.setName("名字"+i);
//			st.setAge("年龄"+i);
//			st.setAddress("地址"+i);
//			si.save(st);
//		}
		//查询所有数据
		CacheStudentService s = (CacheStudentService)context.getBean("serviceStuImp");
		List list = s.findAll();
		for(int i=0;i<list.size();i++){
			CacheStudent cs = (CacheStudent)list.get(i);
			System.out.println(cs.getName());
		}
		//根据ID删除
//		si.remove("402881e425db297a0125db2983410001");
	}
}



myeclipse8+struts2.1+spring2.5+hibernate3.2+weblogic10配置二级缓存时提示错误_第4张图片



你可能感兴趣的:(java,Hibernate,weblogic,cache,orm)