当前位置:编程学习 > JAVA >>

SSH高手进 配置问题

[i][/i]版本:Struts 2.3.14 Spring3.0.0 Hibernate3.3.2 
依赖的jar包:

web.xml 配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- spring context load listener;order to support struts2 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
  <!-- spring beans.xml classpath set -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>


<!-- welcome file list -->
  <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- struts2 config -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,classpath:struts.xml</param-value>
</init-param>
   </filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
 
</web-app>


beans.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:context="http://www.springframework.org/schema/context"
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.xsd
           http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/aop
          http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<!-- <aop:aspectj-autoproxy /> -->
<context:annotation-config />
<context:component-scan base-package="com.sinpertime" />

<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

<!-- dataSource dbpc database config file classpath-->
<context:property-placeholder location="classpath:jdbc.properties" />

<!-- dataSource dbpc -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

<!-- sessionFactory annotatedClasses-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list><value>com.sinpertime.model</value></list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<!-- hibernate template 
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean> -->

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

<!-- aop: all service add transaction -->
<aop:config>
<aop:pointcut id="txServicePointcut"
expression="execution(public * com.sinpertime.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="txServicePointcut" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="getUser"/>
<tx:method name="save" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
</beans>


struts.xml 配置

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <!-- constant name="devMode" value="true" / -->
    <package name="default" namespace="/" extends="struts-default">
        <action name="user" class="com.sinpertime.action.UserAction">
            <result>/registerSuccess.jsp</result>
        </action>
    </package>
</struts>


UserAction 类

package com.sinpertime.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.sinpertime.service.IUserService;

@Component("user")
@Scope("prototype")
public class UserAction extends ActionSupport{

@Override
public String execute() throws Exception {
 System.out.println("action ........");
return "success";
}

}


registerSuccess.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'registerSuccess.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
    Success
  </body>
</html>


--------------------编程问答-------------------- tomcat启动 控制台内容:

2013-12-14 1:03:30 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\jdk1.6.0_13\bin;D:\apache-tomcat-6.0.20\bin
2013-12-14 1:03:30 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2013-12-14 1:03:30 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1043 ms
2013-12-14 1:03:30 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2013-12-14 1:03:30 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.20
2013-12-14 1:03:32 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2013-12-14 1:03:32 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization started
2013-12-14 1:03:32 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing Root WebApplicationContext: startup date [Sat Dec 14 01:03:32 CST 2013]; root of context hierarchy
2013-12-14 1:03:33 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
2013-12-14 1:03:35 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
信息: Loading properties file from class path resource [jdbc.properties]
2013-12-14 1:03:36 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a80183: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,user,iUserDao,iUserService,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,txServicePointcut,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice]; root of factory hierarchy
2013-12-14 1:03:39 org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
信息: Building new Hibernate SessionFactory
poc2013-12-14 1:03:43 org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
信息: Using DataSource [org.apache.commons.dbcp.BasicDataSource@18fdb73] of Hibernate SessionFactory for HibernateTransactionManager
h2013-12-14 1:03:43 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization completed in 10506 ms
o2013-12-14 1:03:44 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name classpath:struts.xml, skipping
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [classpath:struts.xml]
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (spring) for (com.opensymphony.xwork2.ObjectFactory)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.FileManagerFactory)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.XWorkConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.CollectionConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.ArrayConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.DateConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.NumberConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.impl.StringConverter)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionPropertiesProcessor)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionFileProcessor)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ConversionAnnotationProcessor)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterCreator)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.TypeConverterHolder)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.TextProvider)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.LocaleProvider)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.ActionProxyFactory)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.mapper.ActionMapper)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (jakarta) for (org.apache.struts2.dispatcher.multipart.MultiPartRequest)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (org.apache.struts2.views.freemarker.FreemarkerManager)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (org.apache.struts2.components.UrlRenderer)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.validator.ActionValidatorManager)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.ValueStackFactory)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionProvider)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.reflection.ReflectionContextFactory)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.PatternMatcher)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (org.apache.struts2.dispatcher.StaticContentLoader)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.UnknownHandlerManager)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (org.apache.struts2.views.util.UrlHelper)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Choosing bean (struts) for (com.opensymphony.xwork2.util.TextParser)
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Initializing Struts-Spring integration...
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Setting autowire strategy to name
2013-12-14 1:03:45 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: ... initialized Struts-Spring integration successfully
2013-12-14 1:03:48 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2013-12-14 1:03:48 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
t2013-12-14 1:03:50 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2013-12-14 1:03:50 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info

2013-12-14 1:03:52 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2013-12-14 1:03:52 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2013-12-14 1:03:52 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/60  config=null
2013-12-14 1:03:52 org.apache.catalina.startup.Catalina start
信息: Server startup in 21736 ms


--------------------编程问答-------------------- 请求user.action后页面显示404 控制台输出下面内容,现在实在找不到问题所在了 希望csdn的大神们来支个招

警告: Could not find action or result
There is no Action mapped for namespace [/] and action name [user] associated with context path [/Demo]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
2013-12-14 1:04:12 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [user] associated with context path [/Demo].
There is no Action mapped for namespace [/] and action name [user] associated with context path [/Demo]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
--------------------编程问答-------------------- tomcat启动时候一切正常 所有配置文件加载OK 由于字数限制问题 在tomcat启动控制台输出的时去掉了一些log提示 --------------------编程问答-------------------- 你访问的路径出现了问题:http://localhost:端口/项目名称/user --------------------编程问答-------------------- 重新加载一下项目试试。。。 --------------------编程问答--------------------
引用 4 楼 u011213572 的回复:
你访问的路径出现了问题:http://localhost:端口/项目名称/user


这样做还是一样的 返回404页面 报错也一样 

引用 5 楼 zhouren1314 的回复:
重新加载一下项目试试。。。
 这样做了N次 没有效果 --------------------编程问答-------------------- 问题刚才已经解决了 原因是:
<!-- struts2 config -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>struts-default.xml,struts-plugin.xml,classpath:struts.xml</param-value>
        </init-param>
   </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
初始化的时候找不到classpath:struts.xml 
这个去掉即可: <init-param>
            <param-name>config</param-name>
            <param-value>struts-default.xml,struts-plugin.xml,classpath:struts.xml</param-value>
        </init-param>
谢谢各位大大
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,