论坛首页 入门技术论坛

配置struts2.0.6+spring2.0.3+hibernane3备忘

浏览 36869 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-04-23  
楼主有的例子中 有没有遇到下面这个帖子中的问题啊
http://www.iteye.com/topic/73332
0 请登录后投票
   发表时间:2007-04-25  
关注一下,最近正要用
0 请登录后投票
   发表时间:2007-06-01  
请把程序文件上传上来好吗?供学习一下。
0 请登录后投票
   发表时间:2007-06-18  
感谢楼主的知识分享!

我也跟着先做了一个struts2的helloworld列子,启动成功,struts2的架子搭好了,准备把spring2和hibernate3整合到其中,以下是我的一些配置文件:
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Struts2test</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>Struts2test.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/*.xml</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>
/WEB-INF/classes/conf/log4j.properties
</param-value>
</context-param>

<!-- 著名 Character Encoding filter -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<!--Hibernate Open Session in View Filter-->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<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>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!-- 让hibernate open session in view的荣光也照耀xfire -->
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<!--Spring ApplicationContext 载入 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>


struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<include file="struts-default.xml" /> 
    <include file="struts/example.xml"/>
   
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> 
    <set-property property="contextConfigLocation"   
                  value="/WEB-INF/classes/struts.xml"   
    /> 
</plug-in>
</struts>

struts.properties:
struts.devMode = true
struts.enable.DynamicMethodInvocation = false
#struts.objectFactory = spring   这里有个问题,在struts.xml中已经定义了plugin,在这里还需要再定义这个吗?

以上是我的整合spring的配置文件,但是启动tomcat的时候会报如下错误:
log4j:WARN No appenders could be found for logger (org.apache.catalina.startup.TldConfig).
log4j:WARN Please initialize the log4j system properly.
2007-6-18 7:26:43 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2007-6-18 7:26:43 org.apache.catalina.core.StandardContext start
严重: Context [/struts2test] startup failed due to previous errors
2007-06-18 07:26:43,109 INFO [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/struts2test]] - Shutting down Log4J
2007-6-18 7:26:43 org.apache.catalina.core.StandardContext processTlds
严重: Error reading tld listeners java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.log4j.Category.isEnabledFor(Category.java:757)
at org.apache.commons.logging.impl.Log4JLogger.isTraceEnabled(Log4JLogger.java:327)
at org.apache.catalina.startup.TldConfig.tldScanResourcePaths(TldConfig.java:581)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:282)
at org.apache.catalina.core.StandardContext.processTlds(StandardContext.java:4278)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4115)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
2007-6-18 7:26:43 org.apache.coyote.http11.Http11BaseProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2007-6-18 7:26:43 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2007-6-18 7:26:43 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31  config=null
2007-6-18 7:26:43 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2007-6-18 7:26:43 org.apache.catalina.startup.Catalina start
信息: Server startup in 1422 ms

以下是我加入的jar包:
antlr-2.7.6.jar
asm-2.2.1.jar
cglib-nodep-2.1_3.jar
commons-beanutils-1.7.1-20061106.jar
commons-collections-3.2.jar
commons-dbcp-1.2.1.jar
commons-digester-1.7.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
freemarker-2.3.8.jar
hibernate-3.2.0.ga.jar
jstl-1.1.2.jar
jta-1.0.1B.jar
jtds-1.2.jar
log4j-1.2.8.jar
ognl-2.6.11.jar
spring-2.0.jar
struts2-core-2.0.6.jar
struts2-spring-plugin-2.0.6.jar
xwork-2.0.1.jar
tomcat包就不列出来了

起初我看到是log4j的错误时,我就把web.xml中的log4j去掉,但是启动还报这个错误,我有点困惑,为何一加入spring之后就会报这个错误,为何去掉了log4j后还会报log4j的错误。
0 请登录后投票
   发表时间:2007-06-20  
你是否漏了某些包没加进去?
0 请登录后投票
   发表时间:2007-06-21  
你的spring事务配置用的是1.0的配置呀,不是2.0的
0 请登录后投票
   发表时间:2007-06-29  
内容是很好的,我刚开始学这个东西,你能不能把你这个应用的目录结构说一下拉!!
0 请登录后投票
   发表时间:2007-06-29  
为什么用这个?
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/struts.xml"
/>
</plug-in>
那么strtus2提供的struts2-spring-plugin-2.0.8.jar是干嘛用的呢?
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics