spring读书比较:springmvc配置文件

1、applicationContext.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"

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/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!--扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入-->

<context:component-scanbase-package="com.shxt.*"/>

<!--配置数据源-->

<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close"

p:driverClassname="com.mysql.jdbc.Driver"

p:url="jdbc:mysql://localhost:3306/test"

p:username="root"

p:password="root"/>

<!--配置Jdbc模板-->

<beanid="jdbcTemplate"class="org.springframework.jdbc.core.JdbcTemplate"

p:dataSource-ref="dataSource"/>

<!--配置事务管理器-->

<beanid="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager"

p:dataSource-ref="dataSource"/>

<!--通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务-->

<aop:configproxy-target-class="true">

<aop:pointcutid="serviceMethod"

expression="execution(*com.baobaotao.service..*(..))"/>

<aop:advisorpointcut-ref="serviceMethod"advice-ref="txAdvice"/>

</aop:config>

<tx:adviceid="txAdvice"transaction-manager="transactionManager">

<tx:attributes>

<tx:methodname="*"/>

</tx:attributes>

</tx:advice>

</beans>

2.springmvc-servlet.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

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">

<!--扫描web包,应用Spring的注解-->

<context:component-scanbase-package="com.shxt.web"/>

<!--配置视图解析器,将ModelAndView及字符串解析为具体的页面-->

<bean

class="org.springframework.web.servlet.view.InternalResourceViewResolver"

p:viewclass="org.springframework.web.servlet.view.JstlView"

p:prefix="/WEB-INF/jsp/"

p:suffix=".jsp"/>

</beans>

3.web.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<web-appversion="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">

<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>

<servlet>

<servlet-name>springmvc</servlet-name>

<servlet-class>

org.springframework.web.servlet.DispatcherServlet

</servlet-class>

<load-on-startup>3</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>

</web-app>

相关推荐