1.1整合思路分析
Java Web应用开发经过多年的发展,已经形成了一套成熟的程序结构。一个典型的使用了SpringMVC和Hibernate框架的应用,其结构如下图所示。
SpringMVC+Hibernate应用的程序结构
SpringMVC的主控制器DispatcherServlet接到请求后会调用特定的Controller。在Controller中又会调用业务类(Service)来执行业务逻辑。如果需要访问数据库,业务类则会继续调用数据库访问对象(DAO)。而在数据库访问对象中,则需要调用SessionFactory提供的Session实例的方法执行具体操作。Session最终会通过Connection等JDBC API来实现增删该查等操作,而Connction可以通过配置的数据源(DataSource)来提供。
通过以上分析不难看出,程序执行过程中依赖的方向是Controller—>Service—>DAO—>Session(由SessionFactory提供)—>Connection(由DataSource提供),当使用Spring IOC进行依赖管理时,依赖注入的方向则正好与相反。下面通过对核心配置文件的讲解及功能点的展示来讲解Spring+SpringMVC+Hibernate框架的搭建过程。
1.2 开发环境
开发工具:myeclipse8.6.1
数据库:mysql5.5.23
服务器: tomcat6.0.37
框架版本: spring3.2.2+hibernate3.3.2
1.3 案例开发步骤
步骤一:
在myeclipse8.6中新建web工程SHMvc,拷贝如下包到lib目下:
代码的目录结构如下图所示:
步骤二:
编写web.xml 配置文件,代码如下:
=================================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”
>
<!–
配置统一错误处理页面
start –>
<
error-page
>
<
error-code
>
404
</
error-code
>
<
location
>
/Err404.html
</
location
>
</
error-page
>
<
error-page
>
<
error-code
>
500
</
error-code
>
<
location
>
/Err500.html
</
location
>
</
error-page
>
<!–
配置统一错误处理页面
end –>
<!–
配置登录验证过滤器
start –>
<
filter
>
<
filter-name
>
loginFilter
</
filter-name
>
<
filter-class
>
com.wx.filters.LoginFilter
</
filter-class
>
<!–
不做拦截的请求
–>
<
init-param
>
<
param-name
>
exclusions
</
param-name
>
<
param-value
>
SHMvc/,.js,.gif,.jpg,.jpeg,.png,.css,.ico,
Login.jsp,Login.php,Register.jsp,register.php,CheckUser.php,
ShowOneUser.jsp,ShowResult.jsp,Trans.php,ShowOneUser.php
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
loginFilter
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<!–
配置登录验证过滤器
end –>
<!–druid
连接池监控
config start –>
<
filter
>
<
filter-name
>
DruidWebStatFilter
</
filter-name
>
<
filter-class
>
com.alibaba.druid.support.http.WebStatFilter
</
filter-class
>
<
init-param
>
<
param-name
>
exclusions
</
param-name
>
<
param-value
>
*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
DruidWebStatFilter
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<
servlet
>
<
servlet-name
>
DruidStatView
</
servlet-name
>
<
servlet-class
>
com.alibaba.druid.support.http.StatViewServlet
</
servlet-class
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>
DruidStatView
</
servlet-name
>
<
url-pattern
>
/druid/*
</
url-pattern
>
</
servlet-mapping
>
<!–http://localhost:8080/SHMvc/druid/index.html end–>
<!–
解决
hibernate
延迟加载问题的处理
start –>
<
filter
>
<
filter-name
>
openSessionInViewFilter
</
filter-name
>
<
filter-class
>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</
filter-class
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
openSessionInViewFilter
</
filter-name
>
<
url-pattern
>
*.php
</
url-pattern
>
</
filter-mapping
>
<!–
解决
hibernate
延迟加载问题的处理
end –>
<!–
配置
spring mvc
的字符集过滤
start–>
<
filter
>
<
filter-name
>
encode
</
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
>
<
init-param
>
<
param-name
>
forceEncoding
</
param-name
>
<
param-value
>
true
</
param-value
>
</
init-param
>
</
filter
>
<
filter-mapping
>
<
filter-name
>
encode
</
filter-name
>
<
url-pattern
>
/*
</
url-pattern
>
</
filter-mapping
>
<!–
配置
spring mvc
的字符集过滤
end–>
<!–
配置
springmvc
前端控制器
start–>
<
servlet
>
<
servlet-name
>
springmvc
</
servlet-name
>
<
servlet-class
>
org.springframework.web.servlet.DispatcherServlet
</
servlet-class
>
<
init-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:configs/mvc/springmvc-dispatcher.xml
</
param-value
>
</
init-param
>
<
load-on-startup
>
1
</
load-on-startup
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>
springmvc
</
servlet-name
>
<
url-pattern
>
*.php
</
url-pattern
>
</
servlet-mapping
>
<!–
配置
springmvc
前端控制器
end–>
<!–
加载
log4jstart –>
<
context-param
>
<
param-name
>
log4jConfigLocation
</
param-name
>
<
param-value
>
classpath:configs/log4j.properties
</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>
org.springframework.web.util.Log4jConfigListener
</
listener-class
>
</
listener
>
<!–
加载
log4j end–>
<!–
加载
spring
容器
start–>
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:configs/applicationContext.xml
</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
</
listener
>
<!–
加载
spring
容器
end–>
<
welcome-file-list
>
<
welcome-file
>
Login.jsp
</
welcome-file
>
</
welcome-file-list
>
</
web-app
>
================================================================
web.xml是我们web工程的核心配置所在。在这里,我们配置了统一错误处理、登录验证过滤器、druid连接池监控、解决hibernate延迟加载问题的过滤器、spring mvc的字符集过滤、spring mvc前端控制器、加载log4j、加载spring容器等相关配置。相关代码请看web.xml的注释部分。
重点知识讲解:
(1) Spring需要启动容器才能为其他框架提供服务,由于Web应用程序的人口是被Web服务器控制的,所以,无法在main()方法中通过创建ClassPallXmIApplicationContext对象来启动Spring容器。Spring提供了一个监听器类org.springframework.web.context.ContextLoaderListener来解决这个问题。该监听器实现了ServletContextListener接口,可以在Web容器启动的时候初始化Spring容器。当然,前提是需要在web.xml中配置好这个监听器。具体请参见上面配置代码及相关的注释部分。
(2) Spring为我们提供了一个名为OpenSessionInViewFilter的过滤器,可以和前面提到的事务管理器及HibernateDaoSupport很好地配合。其作用是把一个Hibernate Session和一次完整的请求过程相绑定,在请求开始时开启Session,请求结束时关闭Session。这使得在一次请求的完整周期中,所使用的HibernateSession是唯一的且一直保持开启的可用状态,比较简便地解决了诸如延迟加载等问题。具体请参见上面的配置代码及相关的注释部分。
步骤三:
建立hibernate二级缓存的配置文件,如下所示:
=========================echache.xml==============================
<
ehcache
>
<
diskStore
path
=
“java.io.tmpdir”
/>
<
defaultCache
maxElementsInMemory
=
“100”
eternal
=
“false”
timeToIdleSeconds
=
“120”
timeToLiveSeconds
=
“120”
overflowToDisk
=
“true”
/>
</
ehcache
>
=====================================================================
步骤四:
建立hibernate核心配置文件,如下所示:
======================hibernate.cfg.xml==============================
<!
DOCTYPE
hibernate-configuration
PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”
>
<
hibernate-configuration
>
<
session-factory
>
<!–
配置数据库方言
(
即数据库的类型
) –>
<
property
name
=
“dialect”
>
org.hibernate.dialect.MySQLDialect
</
property
>
<!–
把会话绑定到线程上
–>
<
property
name
=
“current_session_context_class”
>
thread
</
property
>
<!–
是否展示
sql –>
<
property
name
=
“show_sql”
>
true
</
property
>
<!–
是否格式化
sql –>
<
property
name
=
“format_sql”
>
true
</
property
>
<!–
二级缓存的提供类
–>
<
property
name
=
“hibernate.cache.provider_class”
>
org.hibernate.cache.EhCacheProvider
</
property
>
<!–
二级缓存配置文件的路径
–>
<
property
name
=
“hibernate.cache.provider_configuration_file_resource_path”
>
configs/ehcache.xml
</
property
>
<!–
是否开启二级缓存
–>
<
property
name
=
“hibernate.cache.use_second_level_cache”
>
true
</
property
>
<!–
是否开启查询缓存
–>
<
property
name
=
“hibernate.cache.use_query_cache”
>
true
</
property
>
</
session-factory
>
</
hibernate-configuration
>
=====================================================================
步骤五:
建立druid数据源的属性文件,如下所示:
========================= druidConfig.properties=====================
driverClassName=
com.mysql.jdbc.Driver
url=
jdbc\
:
mysql\://localhost\:3306/schooldb
username=
root
password=
123456
#
配置监控统计拦截的
filters
,去掉后监控界面
sql
无法统计
filters=
stat
#
配置初始化大小
initialSize=
6
#
配置初始化最大连接数
maxActive=
20
#
配置最小空闲连接数
minIdle=
3
#
配置获取连接等待超时的时间
,1
分钟
maxWait=
60000
#
检测连接是否有效的
SQL
validationQuery=
SELECT
‘x’
#
申请连接的时候检测,如果空闲时间大于
timeBetweenEvictionRunsMillis
,执行
validationQuery
检测连接是否有效
testWhileIdle=
true
#
申请连接时执行
validationQuery
检测连接是否有效,做了这个配置会降低性能
testOnBorrow=
false
#
归还连接时执行
validationQuery
检测连接是否有效,做了这个配置会降低性能
testOnReturn=
false
#
启用
PSCache
,必须配置大于
0
,当大于
0
时,
poolPreparedStatements
自动触发修改为
true
maxPoolPreparedStatementPerConnectionSize=
20
#
对于长时间不使用的连接强制关闭
removeAbandoned=
true
#
超过
30
秒的空闲连接就可以被关闭了
,
单位是秒
removeAbandonedTimeout=
30
#
配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis=
10000
#
配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis=
30000
=====================================================================
步骤六:
建立log4j的属性文件,如下所示:
========================= log4j.properties=====================
log4j.rootLogger=
INFO,
Console
#Console
log4j.appender.Console=
org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=
org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=
%d
[%t]
%-5p
[%c]
%m%n
=====================================================================
步骤七:
建立spring的核心配置文件,如下所示:
========================= applicationContext.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: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-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”
>
<!–
导入
dao
层和
service
层的
bean
配置
–>
<
import
resource
=
“classpath:configs/spring/applicationContext-dao.xml”
/>
<
import
resource
=
“classpath:configs/spring/applicationContext-service.xml”
/>
<!–
加载
druid
数据源的属性文件
–>
<
bean
id
=
“config”
class
=
“org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer”
>
<
property
name
=
“location”
>
<
value
>
classpath:configs/druidConfig.properties
</
value
>
</
property
>
</
bean
>
<!– druid
数据源的配置
–>
<
bean
id
=
“druidDataSource”
class
=
“com.alibaba.druid.pool.DruidDataSource”
init-method
=
“init”
destroy-method
=
“close”
>
<
property
name
=
“driverClassName”
value
=
“${driverClassName}”
/>
<
property
name
=
“url”
value
=
“${url}”
/>
<
property
name
=
“username”
value
=
“${username}”
/>
<
property
name
=
“password”
value
=
“${password}”
/>
<
property
name
=
“filters”
value
=
“${filters}”
/>
<
property
name
=
“initialSize”
value
=
“${initialSize}”
/>
<
property
name
=
“maxActive”
value
=
“${maxActive}”
/>
<
property
name
=
“minIdle”
value
=
“${minIdle}”
/>
<
property
name
=
“maxWait”
value
=
“${maxWait}”
/>
<
property
name
=
“validationQuery”
value
=
“${validationQuery}”
/>
<
property
name
=
“testWhileIdle”
value
=
“${testWhileIdle}”
/>
<
property
name
=
“testOnBorrow”
value
=
“${testOnBorrow}”
/>
<
property
name
=
“testOnReturn”
value
=
“${testOnReturn}”
/>
<
property
name
=
“maxPoolPreparedStatementPerConnectionSize”
value
=
“${maxPoolPreparedStatementPerConnectionSize}”
/>
<
property
name
=
“removeAbandoned”
value
=
“${removeAbandoned}”
/>
<
property
name
=
“removeAbandonedTimeout”
value
=
“${removeAbandonedTimeout}”
/>
<
property
name
=
“timeBetweenEvictionRunsMillis”
value
=
“${timeBetweenEvictionRunsMillis}”
/>
<
property
name
=
“minEvictableIdleTimeMillis”
value
=
“${minEvictableIdleTimeMillis}”
/>
</
bean
>
<!–
配置
sessionFactory
,即在这里整合
hibernate–>
<
bean
id
=
“sessionFactory”
class
=
“org.springframework.orm.hibernate3.LocalSessionFactoryBean”
>
<
property
name
=
“dataSource”
ref
=
“druidDataSource”
></
property
>
<
property
name
=
“configLocation”
>
<
value
>
classpath:configs/hibernate.cfg.xml
</
value
>
</
property
>
<
property
name
=
“mappingLocations”
>
<
list
>
<
value
>
classpath:com/wx/entitys/*.hbm.xml
</
value
>
</
list
>
</
property
>
</
bean
>
<!–
配置
sessionFactory end–>
<!–
统一事务处理的配置
start –>
<
bean
id
=
“txManager”
class
=
“org.springframework.orm.hibernate3.HibernateTransactionManager”
>
<
property
name
=
“sessionFactory”
ref
=
“sessionFactory”
></
property
>
</
bean
>
<
tx:advice
id
=
“txAdvise”
transaction-manager
=
“txManager”
>
<
tx:attributes
>
<
tx:method
name
=
“find*”
read-only
=
“true”
/>
<
tx:method
name
=
“search*”
read-only
=
“true”
/>
<
tx:method
name
=
“query*”
read-only
=
“true”
/>
<
tx:method
name
=
“get*”
read-only
=
“true”
/>
<
tx:method
name
=
“add*”
propagation
=
“REQUIRED”
/>
<
tx:method
name
=
“save*”
propagation
=
“REQUIRED”
/>
<
tx:method
name
=
“do*”
propagation
=
“REQUIRED”
/>
<
tx:method
name
=
“update*”
propagation
=
“REQUIRED”
/>
<
tx:method
name
=
“del*”
propagation
=
“REQUIRED”
/>
</
tx:attributes
>
</
tx:advice
>
<
aop:config
>
<
aop:pointcut
expression
=
“execution(*com.wx.service.*.*(..))”
id
=
“myCut”
/>
<
aop:advisor
advice-ref
=
“txAdvise”
pointcut-ref
=
“myCut”
/>
</
aop:config
>
<!–
统一事务处理的配置
end –>
</
beans
>
=====================================================================
步骤八:
编写dao层的配置文件applicationContext-dao.xml,如下所示:
===================== applicationContext-dao.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: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-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”
>
<
bean
id
=
“userDao”
class
=
“com.wx.dao.user.UserDaoImpl”
>
<
property
name
=
“sessionFactory”
ref
=
“sessionFactory”
>
</
property
>
</
bean
>
<
bean
id
=
“acctDao”
class
=
“com.wx.dao.account.AcountDaoImpl”
>
<
property
name
=
“sessionFactory”
ref
=
“sessionFactory”
>
</
property
>
</
bean
>
<
bean
id
=
“studentDao”
class
=
“com.wx.dao.school.StudentDaoImpl”
>
<
property
name
=
“sessionFactory”
ref
=
“sessionFactory”
>
</
property
>
</
bean
>
<
bean
id
=
“deptDao”
class
=
“com.wx.dao.school.DepartmentDaoImpl”
>
<
property
name
=
“sessionFactory”
ref
=
“sessionFactory”
>
</
property
>
</
bean
>
</
beans
>
=====================================================================
步骤九:
编写service层的配置文件applicationContext-service.xml,如下所示:
====================applicationContext-service.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: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-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”
>
<
bean
id
=
“userService”
class
=
“com.wx.service.UserService”
>
<
property
name
=
“userDao”
ref
=
“userDao”
></
property
>
</
bean
>
<
bean
id
=
“schoolService”
class
=
“com.wx.service.SchoolService”
>
<
property
name
=
“deptDao”
ref
=
“deptDao”
></
property
>
<
property
name
=
“studentDao”
ref
=
“studentDao”
></
property
>
</
bean
>
<
bean
id
=
“acctService”
class
=
“com.wx.service.AccountService”
>
<
property
name
=
“acctDao”
ref
=
“acctDao”
></
property
>
</
bean
>
</
beans
>
=====================================================================
步骤十:
编写spring mvc的核心配置文件springmvc-dispatcher.xml,如下所示:
==================== springmvc-dispatcher.xml==================
<?
xml
version
=
“1.0”
encoding
=
“UTF-8”
?>
<!
DOCTYPE
beans
PUBLIC
“-//SPRING//DTDBEAN//EN”
“http://www.springframework.org/dtd/spring-beans.dtd”
>
<
beans
>
<!–
导入控制器的
bean
配置
–>
<
import
resource
=
“classpath:configs/mvc/springmvc-controler.xml”
/>
<!–
视图解析器
–>
<
bean
id
=
“resourceView”
class
=
“org.springframework.web.servlet.view.InternalResourceViewResolver”
>
<
property
name
=
“prefix”
value
=
“/”
></
property
>
<
property
name
=
“suffix”
value
=
“.jsp”
></
property
>
</
bean
>
<!–
映射处理器
–>
<
bean
id
=
“simpleUrlMapping”
class
=
“org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”
>
<
property
name
=
“mappings”
>
<
props
>
<
prop
key
=
“/Login.php”
>
userControl
</
prop
>
<
prop
key
=
“/Quit.php”
>
userControl
</
prop
>
<
prop
key
=
“/Trans.php”
>
acctControl
</
prop
>
<
prop
key
=
“/GetAllDept.php”
>
deptControl
</
prop
>
<
prop
key
=
“/QueryStu.php”
>
studentControl
</
prop
>
<
prop
key
=
“/Register.php”
>
userControl
</
prop
>
<
prop
key
=
“/ShowOneUser.php”
>
userControl
</
prop
>
<
prop
key
=
“/CheckUser.php”
>
userControl
</
prop
>
</
props
>
</
property
>
</
bean
>
<!–
方法名称解析器
–>
<
bean
id
=
“springMethodNameResolver”
class
=
“org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver”
>
<
property
name
=
“mappings”
>
<
props
>
<
prop
key
=
“/Login.php”
>
login
</
prop
>
<
prop
key
=
“/Quit.php”
>
quit
</
prop
>
<
prop
key
=
“/Trans.php”
>
doTransfer
</
prop
>
<
prop
key
=
“/GetAllDept.php”
>
getAllDeptNames
</
prop
>
<
prop
key
=
“/QueryStu.php”
>
queryAllStu
</
prop
>
<
prop
key
=
“/Register.php”
>
register
</
prop
>
<
prop
key
=
“/ShowOneUser.php”
>
showOne
</
prop
>
<
prop
key
=
“/CheckUser.php”
>
isUserExist
</
prop
>
</
props
>
</
property
>
</
bean
>
</
beans
>
=====================================================================
步骤十一:
编写控制器的配置文件springmvc-controler.xml,如下所示:
==================== springmvc-controler.xml==============================
<?
xml
version
=
“1.0”
encoding
=
“UTF-8”
?>
<!
DOCTYPE
beans
PUBLIC
“-//SPRING//DTDBEAN//EN”
“http://www.springframework.org/dtd/spring-beans.dtd”
>
<
beans
>
<
bean
id
=
“userControl”
class
=
“com.wx.controler.user.UserControl”
>
<
property
name
=
“methodNameResolver”
ref
=
“springMethodNameResolver”
>
</
property
>
<
property
name
=
“userServ”
ref
=
“userService”
></
property
>
</
bean
>
<
bean
id
=
“acctControl”
class
=
“com.wx.controler.account.AccountControl”
>
<
property
name
=
“methodNameResolver”
ref
=
“springMethodNameResolver”
>
</
property
>
<
property
name
=
“acctServ”
ref
=
“acctService”
></
property
>
</
bean
>
<
bean
id
=
“deptControl”
class
=
“com.wx.controler.school.DepartControl”
>
<
property
name
=
“methodNameResolver”
ref
=
“springMethodNameResolver”
>
</
property
>
<
property
name
=
“schoolServ”
ref
=
“schoolService”
></
property
>
</
bean
>
<
bean
id
=
“studentControl”
class
=
“com.wx.controler.school.StudentControl”
>
<
property
name
=
“methodNameResolver”
ref
=
“springMethodNameResolver”
>
</
property
>
<
property
name
=
“schoolServ”
ref
=
“schoolService”
></
property
>
</
bean
>
</
beans
>
=====================================================================
说明:其它的java类和jsp代码不一一列出,因为实在太多了,有需要请联系我。
步骤十二:
启动tomcat,发布项目,在地址栏分别输入 http://localhost:8080/SHMvc
进行测试。 登录后的结果如图所示:
联系作者: