赞
踩
导入ssm框架所需的几十个jar包。导入lib目录下
需要注意,创建项目时一定要勾选生成web.xml
<!-- 配置spring -->
<!-- 指定配置文件,及所在的目录 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<!-- 配置监听器加载spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
配置SpringMvc
<!-- SpringMVC -->
<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:spring/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 配置注解扫描包 -->
<context:component-scan base-package="com.lvan.controller" />
<!-- 处理器适配和映射器 -->
<mvc:annotation-driven />
<!-- 内部视图处理器 配置之后,jsp页面就可以放在/WEB-INF/jsp/目录下 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db_ssm
jdbc.username=root
jdbc.password=root
<!-- 配置jdbc属性引用文件路径 jdbc.properties的路径 效果类似import导包 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 使用阿里巴巴的 DruidDataSource类来创建数据库连接的基本对象--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <!-- 配置生成Mybatis SqlSessionFactory基本信息 --> <bean class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 配置mybatis配置所在目录 --> <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /> <!-- 指定mybatis的数据源配置 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置mybatis中mapper接口所在的包 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.lvan.mapper" /> </bean>
<!-- 配置事务所在的包 -->
<context:component-scan base-package="com.lvan.service" />
<!-- 配置事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 开启注解方式管理AOP事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。