Spring1.applicationContext.xml
基本内容:
1. 配置数据库连接池
2. 配置Hibernate(sessionFactory和事务)
3. 装配3个bean(相当于struts2)——手动装配
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?xml version=
"1.0"
encoding=
"UTF-8"
?>
<beans xmlns=
"http://www.springframework.org/schema/beans"
xsi:schemaLocation="http:
//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http:
//www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http:
//www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http:
//www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:property-placeholder location=
"classpath:jdbc.properties"
/>
<bean id=
"dataSource"
class
=
"com.mchange.v2.c3p0.ComboPooledDataSource"
>
<property name=
"user"
value=
"${user}"
></property>
<property name=
"password"
value=
"${password}"
></property>
<property name=
"jdbcUrl"
value=
"${url}"
></property>
<property name=
"driverClass"
value=
"${driver}"
></property>
</bean>
<!-- 整合 Hibernate -->
<bean id=
"sessionFactory"
class
=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<property name=
"dataSource"
ref=
"dataSource"
></property>
<property name=
"configLocation"
value=
"classpath:hibernate.cfg.xml"
></property>
</bean>
<bean id=
"transactionManager"
class
=
"org.springframework.orm.hibernate3.HibernateTransactionManager"
>
<property name=
"sessionFactory"
ref=
"sessionFactory"
></property>
</bean>
<tx:advice transaction-manager=
"transactionManager"
id=
"txAdvice"
>
<tx:attributes>
<tx:method name=
"get*"
read-only=
"true"
/>
<tx:method name=
"*"
/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression=
"execution(* net.lampbrother.ssh.*ServiceImpl.*(..))"
id=
"txPointcut"
/>
<aop:advisor advice-ref=
"txAdvice"
pointcut-ref=
"txPointcut"
/>
</aop:config>
<bean id=
"customerDao"
class
=
"net.lampbrother.ssh.CustomerDao"
>
<property name=
"sessionFactory"
ref=
"sessionFactory"
/>
</bean>
<bean id=
"customerService"
class
=
"net.lampbrother.ssh.CustomerServiceImpl"
>
<property name=
"customerDao"
ref=
"customerDao"
></property>
</bean>
<bean id=
"cusotmerAction"
class
=
"net.lampbrother.ssh.CusotmerAction"
>
<property name=
"customerService"
ref=
"customerService"
></property>
</bean>
</beans>
|
Spring2.
web.xml
主要内容:
1.配置struts2
2.配置spring
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?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"
xmlns:web=
"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id=
"WebApp_ID"
version=
"2.5"
>
<!-- 配置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>
<!-- 配置Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-
class
>org.springframework.web.context.ContextLoaderListener</listener-
class
>
</listener>
</web-app>
|
2964

被折叠的 条评论
为什么被折叠?



