因为这是个基于spring的web应用,所以当然我们从web.xml看起:
1
|
<?
xml
version
=
"1.0"
encoding
=
"ISO-8859-1"
?> <
web-app
xmlns
=
"http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version
=
"2.4"
>
<!-- - Location of the XML file that defines the root application context - Applied by ContextLoaderListener. -->
<
context-param
> <
param-name
>contextConfigLocation</
param-name
> <
param-value
> /WEB-INF/config/application-config.xml </
param-value
> </
context-param
>
<!-- - Loads the root application context of this web app at startup. - The application context is then available via - WebApplicationContextUtils.getWebApplicationContext(servletContext). -->
<
listener
> <
listener-class
>org.springframework.web.context.ContextLoaderListener</
listener-class
> </
listener
> <
servlet
> <
servlet-name
>ViewRendererServlet</
servlet-name
> <
servlet-class
>org.springframework.web.servlet.ViewRendererServlet</
servlet-class
> </
servlet
> <
servlet-mapping
> <
servlet-name
>ViewRendererServlet</
servlet-name
> <
url-pattern
>/WEB-INF/servlet/view</
url-pattern
> </
servlet-mapping
> </
web-app
>
|
在第23-25行表示了我们进入spring框架,这个大家都知道。
在第11-16行,定义了Spring的配置文件,我当时设计时候,还是采用了多配置文件结构,所以在应用层,我只指定了这1个配置文件,这个配置文件定义了Spring应用的一些宏观的内容:
这个文件在/WEB-INF/config/applicatino-config.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: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" > <!-- Activates annotation-based bean configuration --> <context:annotation-config /> <!-- Scans for application @Components to deploy to spring container --> <context:component-scan base-package="xx.xx.xx.handlers" /> <context:component-scan base-package="xx.xx.xx.service.impl" /> <context:component-scan base-package="xx.xx.xx.portlet" /> </beans>
我这里只开启了注解配置,并且启用了java包扫描,所以被我罗列的包中的所有Spring注解都会被扫描到,并且在Spring Application Context加载时自动实例化对应的被标注的 bean.
本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1138827,如需转载请自行联系原作者