ssh整合随笔(注解方式,Spring 管理action)
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Spring配置文件位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:Beans.xml
</param-value>
</context-param> <!--啟動Spring的Listener -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> <!--編碼Filter,不過貌似沒用 -->
<filter>
<filter-name>Encoding</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>
<filter-mapping>
<filter-name>Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Hibernate 延時加載 -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter </filter-class> <init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!--Struts2 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.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">
<!--注解支持 -->
<context:annotation-config />
<!--让Spring扫描的包 -->
<context:component-scan base-package="zp.ssh..*"> </context:component-scan>
<!-- 数据库文件位置 -->
<context:property-placeholder location="classpath*:jdbc.properties" />
<!--配置dbcp连接池 -->
<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> <!-- hibernate的SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="zp.ssh"></property> <property name="mappingLocations">
<list>
</list>
</property> <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="current_session_context_class">thread</prop> </props>
</property>
</bean> <!-- <bean id="hl" class="zp.ssh.action.HelloWorldAction"/> --> </beans>
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>
<!-- 用Spring产生Action -->
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="user" extends="struts-default">
<!-- hl是Action类中的注解名称。因为要交给Spring管理,所以class属性不写完整的类名,写Spring装载的Bean的标识符 -->
<action name="helloworld" class="hl" >
<result name="success">welcome.jsp</result>
<result name="error">error.jsp</result>
<result name="input">index.jsp</result>
</action> </package> </struts>
示例action
package zp.ssh.action; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; import zp.ssh.service.MyService;
//这个hl就是struts.xml中的class属性填的东西
@Component("hl")
public class HelloWorldAction extends ActionSupport { @Autowired
private MyService myService;
public HelloWorldAction(){
System.out.println("action被创建");
}
public String execute() throws Exception {
myService.Service();
return SUCCESS;
}
}
ssh整合随笔(注解方式,Spring 管理action)的更多相关文章
- Spring Boot整合Mybatis(注解方式和XML方式)
其实对我个人而言还是不够熟悉JPA.hibernate,所以觉得这两种框架使用起来好麻烦啊. 一直用的Mybatis作为持久层框架, JPA(Hibernate)主张所有的SQL都用Java代码生成, ...
- ssh整合之七注解结合xml形式
1.我们之前的纯xml的方式,我们的配置文件很多,我们可以使用注解结合xml的方式进行开发,这样的话,我们的配置文件,会少很多,同时,我们可以直接在类中看到配置,这样,我们就可以快速地搭建一个ssh整 ...
- Java进阶知识26 SSH整合(Struts2、Spring、Hibernate)
1.我用到的jar包 2.整合实例 2.1.数据库建表语句 create database school; -- 创建数据库 use school; -- 使用school数据库 create tab ...
- SSH整合(Struts2+hibernate+spring)
1.创建表 create table t_user( id int primary key auto_increment, username varchar(50), password varchar ...
- 在ssh框架中注解方式需要注意的几个问题
1.注解方式的时候 Spring 2.5 引入了 @Autowired 注释,它可以对类成员变量.方法及构造函数进行标注,完成自动装配的工作. 通过 @Autowired的使用来消除 set ,get ...
- Ibatis,Spring整合(注解方式注入)
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- ssh整合之五struts和spring整合
1.首先,我们需要先分析一下,我们的spring容器在web环境中,只需要一份就可以了 另外,就是我们的spring容器,要在我们tomcat启动的时候就创建好了(包括其中的spring的对象),怎么 ...
- SSH整合 第三篇 Spring的加入
1.思路和想法. 目前理解到的,觉得是的,可能的,应该这样的……………… Spring的两大核心是IoC和AOP Ioc:帮助实例化对象,加载到容器中,在注入到需要用到的地方.这样就可以减少在不同的方 ...
- 零基础学习java------40---------Maven(maven的概念,安装,maven在eclipse中使用),springboot(spring整合springmvc(注解),spring整合mybatis(常见的配置文件)),前端页面(bootstrap软件)
一 maven 1. Maven的相关概念 1.1 项目开发中遇到的问题 (1)都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? (2)为什么在我的机器上可以正常打包,而配置管理 ...
随机推荐
- 学习使用:before和:after伪元素
http://www.w3cplus.com/css3/learning-to-use-the-before-and-after-pseudo-elements-in-css.html
- pascal矩阵
帕斯卡矩阵 1.定义 帕斯卡矩阵:由杨辉三角形表组成的矩阵称为帕斯卡(Pascal)矩阵. 杨辉三角形表是二次项 (x+y)^n 展开后的系数随自然数 n 的增大组成的一个三角形表. 如4 ...
- Quailty and Binary Operation
Quailty and Binary Operation 题意 分别给\(N,M(N,M \le 50000)\)两个数组\(A\)和\(B\),满足\(0 \le A_i,B_i \le 50000 ...
- spark新能优化之数据本地化
数据本地化的背景: 数据本地化对于Spark Job性能有着巨大的影响.如果数据以及要计算它的代码是在一起的,那么性能当然会非常高.但是,如果数据和计算它的代码是分开的,那么其中之一必须到另外一方的机 ...
- spring beans源码解读之 ioc容器之始祖--DefaultListableBeanFactory
spring Ioc容器的实现,从根源上是beanfactory,但真正可以作为一个可以独立使用的ioc容器还是DefaultListableBeanFactory,因此可以这么说, DefaultL ...
- Wireshark抓包实例分析TCP重复ACK与乱序
转载请在文首保留原文出处: EMC 中文支持论坛https://community.emc.com/go/chinese 介绍 TCP 的一大常见问题在于重复 ACK 与快速重传.这一现象的发生也是由 ...
- JSBinding + SharpKit / 安装SharpKit以及添加SharpKit工程
本文说明如何往 sln 中添加 SharpKit 工程,以及配置. SharpKit 工程用于将 C# 源代码编译成 JS 代码. QQ群 189738580 1. 安装SharpKit 到 sha ...
- ubuntu下如何安装wxpython
1.运行时缺失wx库,如何安装 Error:ImportError: No module named wx 解决方法:sudo apt-get install python-wxgtk2.8 pyth ...
- mysql学习之-三种安装方式与版本介绍
MYSQL版本介绍 mysql分alpha,beta,rc,GA四个版本. alpha 暗示这是一个以展示新特性为目的的版本,存在比较多的不稳定因素,还会向代码中添加新新特性beta 以后的beta ...
- SQLServer中临时表与表变量的区别分析
临时表 临时表与永久表相似,只是它的创建是在Tempdb中,它只有在一个数据库连接结束后或者由SQL命令DROP掉,才会消失,否则就会一直存在.临时表在创建的时候都会产生SQL Server的系统日志 ...