package com.AppServer.action;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import com.AppServer.bean.User;
import com.AppServer.dao.UserDAO;
import com.AppServer.service.UserService;
import com.demo.interceptor.MethodCacheInterceptor;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@Controller
@ParentPackage("struts-default")
@Namespace(value = "msgAction")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class MsgAction extends ActionSupport {
private String username;
private String password;
@Resource
private UserService userService;
@Action(value = "msg" , results = { @Result(name = "success", location = "/success.jsp"),
@Result(name = "failure", location = "/failure.jsp"),
@Result(name = "error", location = "/login.jsp")})
//获取用户信息
public String getInfo() {
System.out.println("进来玩");
return SUCCESS;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
url访问如下:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do
访问之后没报错,没进去getInfo这个方法
struts2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- 指定Web应用的默认编码,相当于调用request的setCharacterEncoding方法 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 当Struts2的配置文件修改后,系统是否自动重新加载配置文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 开发模式下使用,这样可以打印出更详细的日志信息 -->
<constant name="struts.devMode" value="true" />
<!-- 默认的视图主题 -->
<constant name="struts.ui.theme" value="simple" />
<!-- 把Action对象交给Spring创建和管理 -->
<constant name="struts.objectFactory" value="spring" />
<!-- Struts2处理的请求后缀,默认值是action -->
<constant name="struts.action.extension" value="do" />
<!-- 国际化资源文件
<constant name="struts.custom.i18n.resources" value="globalMessages" />
-->
<package name="msg" extends="struts-default">
<default-action-ref name="indexPage" />
<global-results>
<result name="exceptionPage">/error/exceptionPage.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="exceptionPage" exception="java.lang.Exception" />
</global-exception-mappings>
<action name="indexPage">
<result>/login.jsp</result>
</action>
<!-- <action name="msg" method="getInfo" class="com.AppServer.action.MsgAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.jsp</result>
<result name="error">/login.jsp</result>
</action> -->
</package>
application.xml:
<?xml version="1.0" encoding="UTF-8" ?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" 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-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"
default-autowire="byName" default-lazy-init="true">
<!-- 说明:下面有的Bean配置提供了多种方案,请根据需要采用某一种(别忘了注释掉其他同类方案) -->
<!-- 自动扫描Spring注解配置 并保证@Required,@Autowired的属性被注入-->
<context:component-scan base-package="com" />
<!-- 自动加载属性配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置数据源:方法一,使用C3P0方式(推荐) -->
<!-- <context:property-placeholder location="classpath:jdbc.properties"/> -->
<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池启动时的初始值 -->
<property name="password" value="${jdbc.password}"/>
<!-- 连接name="initialSize" value="${initialSize}"/>-->
<property name="initialSize" value="1"/>
<!-- 连接池的最大值 -->
<property name="maxActive" value="500"/>
<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
<property name="maxIdle" value="2"/>
<!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="1"/>
</bean>
<!-- 配置数据源:方法二,使用DBCP方式(不推荐) -->
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
-->
<!-- 配置数据源:方法三,使用JNDI方式 -->
<!--
<jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" />
-->
<!-- 配置Hibernate的数据源代理工厂:方法一,使用p属性通配符,按文件名搜索匹配的映射文件 -->
<!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" >
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
</props>
</property>
加载hibernate的jpa注解形式实体
<property name="packagesToScan">
<list>
<value>com.xmm.demo.domain*</value>
</list>
</property>
</bean> -->
<!-- 配置Hibernate的数据源代理工厂:方法二,使用list集合,按文件名搜索匹配的映射文件 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="mappingLocations">
<list>
<value>classpath*:/com/**/*.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
</props>
</property>
</bean>
<!-- 配置Hibernate的数据源代理工厂:方法三,使用p属性通配符,按目录搜索映射文件 -->
<!--
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
</props>
</property>
</bean>
-->
<!-- 配置Hibernate的数据源代理工厂:方法四,使用hibernate.cfg.xml -->
<!--
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml">
</bean>
-->
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<!-- 配置声明式事务:方法一,在Service实现类或者public实现方法上使用注解@Transactional,则此类或方法就会启用事务机制 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->
<!-- 配置声明式事务:方法二,使用tx/aop命名空间的配置(其实还有方法三,由于快要过时不推荐使用了,这里就不给出方法三的配置了) -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="search*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" />
</aop:config>
<!-- 下面三个Bean的配置可有可无,但配置后用处更大,通常用于BaseDao类、其他Dao类或特殊工具类中 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"
p:sessionFactory-ref="sessionFactory" />
<bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport"
p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/>
<bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/>
tomcat6.0:服务器运行正常:
九月 21, 2015 4:22:24 上午 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:\Java\jdk1.7.0\bin;E:\tomcat6\bin
九月 21, 2015 4:22:25 上午 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 516 ms
九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
九月 21, 2015 4:22:25 上午 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.41
九月 21, 2015 4:22:25 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory AppServer_1.1
九月 21, 2015 4:22:25 上午 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(E:\tomcat6\webapps\AppServer_1.1\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Set web app root system property: 'webapp.root' = [E:\tomcat6\webapps\AppServer_1.1]
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing log4j from [classpath:log4j.properties]
九月 21, 2015 4:22:26 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
九月 21, 2015 4:22:34 上午 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
九月 21, 2015 4:22:34 上午 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
九月 21, 2015 4:22:34 上午 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/23 config=null
九月 21, 2015 4:22:34 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 9364 ms
测试定时任务:2015-09-21 04:30:00:074
测试定时任务:2015-09-21 04:40:00:004
url访问地址:http://127.0.0.1:8080/AppServer_1.1/msgAction/msg.do
没有进去action的getinfo方法,这是为什么?而且也没有任何的报错!!!!!!!!!!!