一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

MyEclipse下struts2、spring、hibernate整合

 旭龍 2011-03-14

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、使用默認(rèn)的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)默認(rèn)的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" "http://www./dtd/spring-beans.dtd">
<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
嚴(yán)重: 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
嚴(yán)重: Error listenerStart
2008-8-6 9:29:18 org.apache.catalina.core.StandardContext start
嚴(yán)重: Context [/ssh] startup failed due to previous errors

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

解決:
到這里http://commons./downloads/download_pool.cgi下載包,然后,把里面的commons-pool-x.jar復(fù)制到項目的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
嚴(yán)重: 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>

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    九九热这里只有免费精品| 国产内射一级一片内射高清视频| 91偷拍裸体一区二区三区| 亚洲另类欧美综合日韩精品| 麻豆最新出品国产精品| 国产传媒精品视频一区| 国产欧美日韩不卡在线视频| 伊人久久青草地婷婷综合| 成人免费高清在线一区二区| 色丁香一区二区黑人巨大| 日韩美女偷拍视频久久| 久久亚洲午夜精品毛片| 亚洲av秘片一区二区三区| 人妻人妻人人妻人人澡| 亚洲综合色婷婷七月丁香| 日韩在线中文字幕不卡| 微拍一区二区三区福利| 久久精品国产在热久久| 午夜视频免费观看成人| 夫妻激情视频一区二区三区| 国产麻豆精品福利在线| 久久精品久久精品中文字幕| 东京不热免费观看日本| 国产午夜精品久久福利| 国内外免费在线激情视频| 九九热在线视频观看最新| 色哟哟国产精品免费视频| 国产又大又黄又粗又免费| 久久精品国产99精品亚洲| 91精品国产综合久久精品| 精品国产av一区二区三区不卡蜜| 久久99精品日韩人妻| 成人午夜爽爽爽免费视频| 国产一区在线免费国产一区| av国产熟妇露脸在线观看| 午夜福利黄片免费观看| 国产成人午夜在线视频| 亚洲视频在线观看免费中文字幕| 国产又粗又猛又长又大| 日韩精品毛片视频免费看| 中文字幕日韩欧美亚洲午夜|