<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/aaaa" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<!-- 工厂bean,它的作用就是解析配置(数据源、别名等)-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 采用自动扫描方式创建mapper bean(单个更新模式) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mapper"/>
</bean>
<!-- 在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,
如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean-->
<context:component-scan base-package="com/service" />
<context:component-scan base-package="com/controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 配置sqlSessionFactory -->
<!-- 配置扫描器 -->
<!-- 配置Spring的事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven />
</beans>
web.xml↓↓↓↓↓↓↓↓↓↓↓↓↓
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/login</url-pattern>
<url-pattern>/reg</url-pattern>
<url-pattern>/CreatCode.do</url-pattern>
<url-pattern>/send</url-pattern>
</servlet-mapping>
struts2 的web配置文件↓↓↓↓↓↓↓↓↓↓↓↓↓↓
<servlet>
<servlet-name>SumServlet</servlet-name>
<servlet-class>com.servlet.SumServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SumServlet</servlet-name>
<url-pattern>/SumServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>