免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
MyEclipse下struts2、spring、hibernate整合

1、MyEclipse下建立新的Web Porject 

2、Copy Struts2的lib文件到工程的WEB-INF/lib下非*-plugin-2.0.6.jar的所有的包加上struts2-spring- plugin-2.0.6.jar,最小的包可以在struts-2.0.6\apps\struts2-blank-2.0.6\WEB-INF\ lib下找到,不過因為使用Spring、Hiberate那點包是不夠用的 

3.1、工程名上右鍵->MyEclipse->Add Spring Capabilities點擊出現(xiàn)對話框 

3.2、由于我用的MyEclipse中Spring的插件是1.2的,所以沒使用MyEclipse下的包,不選擇MyEclipse Libraries 

3.3、選中Copy checked library contents to project folder (TLDs always copied) 

3.4、使用默認的Library Folder:/WebRoot/WEB-INF/lib,Next 

3.5、Folder點周Brower選中項目的WebRoot/WEB-INF/ 

3.6、點擊Finish 

4、配置MyEclipse數(shù)據(jù)庫設(shè)置 

4.1、菜單Windows->Preferences->MyEclipse->Database Explorer->Drivers 

4.2、點擊New設(shè)置數(shù)據(jù)庫連接,例: 
Driver template : Oracle (Thin driver) 
Driver name : Oracle (Thin driver) 
Connection URL : jdbc:oracle:thin:@<server>[:<1521>]:<database_name> 
Driver JARs: ojdbc14.jar 
Dirver classname : oracle.jdbc.driver.OracleDriver 

4.3、點擊OK、OK 

5、忘了Copy Spring 2的jar包到工程中了,不過沒關(guān)系,現(xiàn)在Copy也一樣,Copy spring-framework-2.0.3\dist\spring.jar 到/WebRoot/WEB-INF/lib下就可以了,如果想Copy專用的包可以Copy spring-framework-2.0.3\dist\modules下的 

5.1、菜單Windows->Open perspective->MyEclipse Database Explorer 

5.2、在DB Brower點右鍵->New 

5.3、配置例子如下: 
Profile name: test 
Driver: Oracle (Thin driver) 
URL: jdbc:oracle:thin:@127.0.0.1:1521:test 
User name: test 
Password: test 
選中Save password 

5.4、點擊Finish 

6.1、配置Hibernate 

6.2 工程名上右鍵->MyEclipse->Add Hiberate Capabilities點擊出現(xiàn)對話框 

6.3、選中Copy checked Library Jars to project forlder and add to build-path 點擊Next 

6.4、選中Spring configuration file (applicationContext.xml)點擊Next 

6.5、選中Existing Spring configuration file,MyEclipse會幫你自動找到Spring Config文件的 

6.6、SessionFactory ID填寫sessionFactory點擊Next 

6.7、Bean Id填寫dataSource,選中DB Profile下剛才建好的test,點擊Next 

6.8、不選擇Create SessionFactory class?點擊Finish 

7、這時候會提示你某些類沒發(fā)現(xiàn),Copy commons-dbcp-1.2.1.jar到lib下就OK了 


8 配置struts.properties文件,指定spring作為struts的IoC容器
struts.objectFactory = spring
(1)默認的autowiring模式是:by name
即如果applicationContext.xml文件中的bean id與struts.xml文件中的action name相同,就
(2)如果要改為其他模式:
struts.objectFactory.spring.autoWire = name|type|auto|constructor

例:

struts.i18n.encoding=ISO-8859-1
struts.locale=de_DE
struts.objectFactory=spring
### Load custom default resource bundles
struts.custom.i18n.resources=testmessages
### XSLT Cache
struts.xslt.nocache = true


9配置web.xml文件,啟動Spring偵聽器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

10 在WEB-INF目錄下的applicationContext.xml文件
例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "<beans default-autowire="autodetect">
<bean id="personManager" class="com.acme.PersonManager"/>
</beans >

11 設(shè)置由Spring來初始化action
11.1  在Spring的applicationContext.xml文件中配置bean(即action類)
11.2  將struts.xml中的action的class屬性,由class名改為Spring中定義的bean名
例如:
(1)applicationContext.xml中,定義bean id是bar
<beans default-autowire="autodetect">
<bean id="bar" class="com.my.BarClass" singleton="false"/>
...
</beans>
(2)struts.xml中,action的class="bar",而不是通常的類名
<package name="secure" namespace="/secure" extends="default">
<action name="bar" class="bar">
<result>bar.ftl</result>
</action>
</package >

啟動運行:
報錯
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
2008-8-6 9:29:16 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2008-8-6 9:29:18 org.apache.catalina.core.StandardContext listenerStart
嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError:org/apache/commons/pool/impl/GenericObjectPool
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
 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:380)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
 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:429)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
 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 org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
 at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
 at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
 at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
 at org.apache.catalina.core.StandardService.start(StandardService.java:516)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
 at java.lang.Class.getDeclaredConstructors0(Native Method)
 at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
 at java.lang.Class.getConstructor0(Unknown Source)
 at java.lang.Class.getDeclaredConstructor(Unknown Source)
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:54)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
 ... 40 more
2008-8-6 9:29:18 org.apache.catalina.core.StandardContext start
嚴重: Error listenerStart
2008-8-6 9:29:18 org.apache.catalina.core.StandardContext start
嚴重: Context [/ssh] startup failed due to previous errors

原因:
找不到 Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
就Apache所提供的基本對象池。

解決:
到這里
http://commons.apache.org/downloads/download_pool.cgi下載包,然后,把里面的commons-pool-x.jar復制到項目的lib文件夾下

錯誤:
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.

解決:
在WEB-INF/class 目錄下建立一個log4j.properties文件,內(nèi)容如下: 
log4j.rootLogger=DEBUG,stdout 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%F:%L) - %m%n 

警告:

信息: Starting Servlet Engine: Apache Tomcat/6.0.13
log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources).
log4j:WARN Please initialize the log4j system properly.
2008-8-6 9:40:09 org.apache.catalina.core.ApplicationContext log
信息: Initializing WebApplicationContext for Struts ActionServlet 'action', module ''
2008-08-06 09:40:29,859 DEBUG (CollectionFactory.java:195) - Creating [java.util.concurrent.ConcurrentHashMap]
 2008-8-6 9:40:29 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2008-08-06 09:40:29,906  INFO (ContextLoader.java:189) - Root WebApplicationContext: initialization started
 2008-08-06 09:40:30,203  INFO (AbstractApplicationContext.java:412) - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1df59bd: display name [Root WebApplicationContext]; startup date [Wed Aug 06 09:40:30 CST 2008]; root of context hierarchy
 2008-08-06 09:40:30,406 DEBUG (CollectionFactory.java:195) - Creating [java.util.concurrent.ConcurrentHashMap]


index.jsp

<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
 <head>
  <title>登錄</title>
  <style type="text/css">
.label {
 font-style: italic;
}

.errorLabel {
 font-style: italic;
 color: red;
}

.errorMessage {
 font-weight: bold;
 color: red;
}
</style>
 </head>
 <s:head theme="ajax" />
 <body>
 <s:debug>
  <s:form action="First">
   <s:textfield name="username" label="用戶名" />
   <s:textfield name="password" label="密碼" />
   <s:submit value="登錄" />
   <s:a href="First.action">登錄</s:a>
  </s:form>
</s:debug>
 </body>
</html>



BUG:
2008-8-6 10:58:02 org.apache.catalina.core.StandardWrapperValve invoke
嚴重: Servlet.service() for servlet jsp threw exception
The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
 at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
 at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:52)
 at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)
 at org.apache.jsp.index_jsp._jspx_meth_s_005fhead_005f0(index_jsp.java:126)
 at org.apache.jsp.index_jsp._jspService(index_jsp.java:94)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)

解決:web.xml添加
<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
解決struts多文件上傳出現(xiàn)的問題
tomcat下配置struts2的Unable to load configuration. - bean - jar:file問題
異步AJAX可能引起的ResponseFacade.sendError
Spring 注入錯誤
struts2中的錯誤--java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
struts2學習歷程--搭建出現(xiàn)的錯誤信息
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服