请参见:
Struts2.2+Spring3.1+Hibernate3.6整合(登录示例)
http://liuzidong.iteye.com/blog/935493
在这个示例作了修改!
参考资料
1 spring通过weblogic配置的jndi实现数据库操作
http://mariosissy.blogbus.com/logs/48042786.html
2 Spring - Weblogic - Hibernate datasource problem
http://forum.springsource.org/showthread.php?t=37872
一 环境:XP+Myeclipse6.6+WebLogic92+JDK1.5
二 具体步骤如下:
jdbc.properties:注意事项:配置的端口:7002是WEBLOGIC服务器创建域是设置的端口
## JNDI Datasource Context.INITIAL_CONTEXT_FACTORY=weblogic.jndi.WLInitialContextFactory Context.PROVIDER_URL=t3://127.0.0.1:7002 JNDI=s2sh RESOURCEREF=true #如果你不想使用 'java:comp/env/'前缀的话请设置下面的值为true, 默认值为false #JNDI=java:comp/env/s2sh #RESOURCEREF=false
bean.xml中配置:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>${JNDI}</value> </property> <property name="resourceRef"> <value>${RESOURCEREF}</value> </property> <property name="jndiEnvironment"> <props> <prop key="java.naming.provider.url">${Context.PROVIDER_URL}</prop> <prop key="java.naming.factory.initial">${Context.INITIAL_CONTEXT_FACTORY}</prop> </props> </property> </bean>
web.xml
<resource-ref> <description>s2sh</description> <res-ref-name>s2sh</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
位置:WEB-INF/weblogic.xml
<?xml version='1.0' encoding='utf-8'?> <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <container-descriptor> <prefer-web-inf-classes>true</prefer-web-inf-classes> </container-descriptor> <context-root>/</context-root> <resource-description> <res-ref-name>s2sh</res-ref-name> <jndi-name>s2sh</jndi-name> </resource-description> </weblogic-web-app>
注意其中的配置很重要!:
<resource-description>
<res-ref-name>s2sh</res-ref-name>
<jndi-name>s2sh</jndi-name>
</resource-description>
不配置会出现错误:
<2011-3-15 下午01时54分31秒 CST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property
'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property
'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'];
remaining name 'oracle'.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao': Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property
'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property
'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'];
remaining name 'oracle'
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
Truncated. see log file for complete stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property
'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property
'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL
[file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'];
remaining name 'oracle'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
Truncated. see log file for complete stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB
-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL [file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-
INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc']; remaining name 'oracle'
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
Truncated. see log file for complete stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL [file:/E:/bea/user_projects/domains/s2shdomain/autodeploy/S2SHJNDI/WEB-
INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc']; remaining name 'oracle'
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
Truncated. see log file for complete stacktrace
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'];
remaining name 'oracle'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:195)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:338)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:252)
at weblogic.jndi.internal.ServerNamingNode_920_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:374)
Truncated. see log file for complete stacktrace
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:178)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
Truncated. see log file for complete stacktrace
>
<2011-3-15 下午01时54分31秒 CST> <Error> <Deployer> <BEA-149231> <Unable to set the activation state to true for the application '_appsdir_S2SHJNDI_dir'.
weblogic.application.ModuleException:
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:894)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:336)
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
javax.naming.NameNotFoundException: Unable to resolve 'jdbc.oracle'. Resolved 'jdbc'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:178)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
Truncated. see log file for complete stacktrace
另外在WebLogic中创建域请参考以下:
图解Weblogic92域创建及与Myeclipse服务配置
http://liuzidong.iteye.com/blog/929740
另外在WEB-INF/lib下加入weblogic.jar文件
以下是各种应用服务器的不同的properties集合:
websphere: java.naming.provider.url->iiop://websphere.machine.domain.com:900 java.naming.factory.initial ->com.ibm.websphere.naming.WsnInitialContextFactory java.naming.factory.url.pkgs ->com.ibm.ws.naming org.omg.CORBA.ORBClass->com.ibm.rmi.iiop.ORB org.omg.CORBA.ORBSingletonClass->com.ibm.rmi.corba.ORBSingleton javax.rmi.CORBA.UtilClass->com.ibm.rmi.javax.rmi.CORBA.Util javax.rmi.CORBA.StubClass->com.ibm.rmi.javax.rmi.CORBA.StubDelegateImpl javax.rmi.CORBA.PortableRemoteObjectClass->com.ibm.rmi.javax.rmi.PortableRemoteObject weblogic: java.naming.factory.initial -> weblogic.jndi.WLInitialContextFactory java.naming.provider.url -> t3://localhost:7001 jboss: ava.naming.factory.initial ->org.jnp.interfaces.NamingContextFactory java.naming.factory.url.pkgs->org.jboss.naming.client java.naming.provider.url ->jnp://10.0.0.18:1099 sunone IMQ ldap: java.naming.provider.url -> ldap://localhost:389/dc=yusong,dc=com java.naming.factory.initial -> com.sun.jndi.ldap.LdapCtxFactory sunone Application Server: java.naming.provider.url -> iiop://192.168.0.34:3700 java.naming.factory.initial -> com.sun.jndi.cosnaming.CNCtxFactory oracle oc4j: java.naming.factory.initial->com.evermind.server.ApplicationClientInitialContextFactory java.naming.provider.url->ormi://localhost/bmpapp
我的异常网推荐解决方案:org.springframework.beans.factory.BeanCreationException:,http://www.myexception.cn/j2ee/10759.html