写点什么

SSM 整合,kafka 教程分享

  • 2021 年 11 月 10 日
  • 本文字数:2908 字

    阅读完需:约 10 分钟

<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-test</artifactId>


<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.aspectj</groupId>


<artifactId>aspectjweaver</artifactId>


<version>1.9.5</version>


</dependency>

2.springMVC 相关 jar 包


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-web</artifactId>


<version>${spring.version}</version>


</dependency>


<dependency>


<groupId>org.springframework</groupId>


<artifactId>spring-webmvc</artifactId>


<version>${spring.version}</version>


</dependency>

3.mybatis 以及 spring 整合 mybatis 相关 jar 包


<dependency>


<groupId>org.mybatis</groupId>


<artifactId>mybatis</artifactId>


<version>3.4.5</version>


</dependency>


<dependency>


<groupId>org.mybatis</groupId>


<artifactId>mybatis-spring</artifactId>


<version>2.0.5</version>


</dependency>

4.连接数据库相关 jar 包


<dependency>


<groupId>com.alibaba</groupId>


<artifactId>druid</artifactId>


<version>1.1.22</version>


</dependency>


<dependency>


<groupId>mysql</groupId>


<artifactId>mysql-connector-java</artifactId>


<version>5.1.47</version>


</dependency>

5.日志相关 jar 包

<dependency>


<groupId>log4j</groupId>


<artifactId>log4j</artifactId>


<version>1.2.17</version>


</dependency>


<dependency>


<groupId>org.slf4j</groupId>


<artifactId>slf4j-api</artifactId>


<version>1.7.10</version>


</dependency>


<dependency>


<groupId>org.slf4j</groupId>


<artifactId>slf4j-log4j12</artifactId>


<version>1.7.10</version>


</dependency>

6.测试相关 jar 包


<dependency>


<groupId>junit</groupId>


<artifactId>junit</artifactId>


<version>4.12</version>


<scope>test</scope>


</dependency>


二、配置文件



1.spring 整合 mybatis spring-mybatis.xml

jdbc.properties

jdbc.driverClassName=com.mysql.jdbc.Driver


jdbc.url=jdbc:mysql://localhost:3306/videos?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8


jdbc.username=root


jdbc.password=123456


initialSize=5


maxActive=20


maxWait=2000

spring-mybatis.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.xsd


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


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


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


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


<context:component-scan base-package="com.liubo.SSMTemplate.service"/>


<context:propert


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


y-placeholder location="classpath:jdbc.properties"/>


<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">


<property name="driverClassName" value="${jdbc.driverClassName}"/>


<property name="url" value="${jdbc.url}"/>


<property name="username" value="${jdbc.username}"/>


<property name="password" value="${jdbc.password}"/>


</bean>


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">


<property name="dataSource" ref="dataSource"/>


<property name="mapperLocations" value="classpath:mappings/*.xml"/>


<property name="configLocation" value="classpath:mybatis-config.xml"/>


</bean>


<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">


<property name="basePackage" value="com.liubo.SSMTemplate.dao"/>


</bean>


<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">


<property name="dataSource" ref="dataSource"/>


</bean>


<tx:annotation-driven transaction-manager="transactionManager"/>


</beans>

2.springMVC 配置文件

spring-mybatis.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:mvc="http://www.springframework.org/schema/mvc"


xsi:schemaLocation="


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


http://www.springframework.org/schema/beans/spring-beans.xsd


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


http://www.springframework.org/schema/context/spring-context.xsd


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


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


<context:component-scan base-package="com.liubo.SSMTemplate.controller"/>


<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">


<property name="prefix" value="/WEB-INF/pages/"/>


<property name="suffix" value=".jsp"/>


</bean>


mvc:default-servlet-handler/


mvc:annotation-driven/


<bean id="myExceptionResolver" class="com.liubo.exception.MyExceptionResolver"/>


mvc:interceptors


mvc:interceptor


<mvc:mapping path="/video/*"/>


<mvc:mapping path="/speaker/*"/>


<mvc:mapping path="/course/*"/>


<bean class="com.liubo.interceptor.LoginInterceptor"/>


</mvc:interceptor>


</mvc:interceptors>


</beans>

3.mybatis 配置文件

mybatis-config.xml

此文件多用与配置一些在 spring-mybatis 文件中不方便配置的东西


<?xml version="1.0" encoding="UTF-8"?>


<!DOCTYPE configuration


PUBLIC "-//mybatis.org//DTD Config 3.0//EN"


"http://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>


<settings>


<setting name="logImpl" value="log4j"/>


<setting name="lazyLoadingEnabled" value="true"/>


<setting name="aggressiveLazyLoading" value="false"></setting>


<setting name="cacheEnabled" value="true"/>


</settings>


<typeAliases>


<package name="com.liubo.domain"/>


<package name="com.liubo.vo"/>


</typeAliases>


</configuration>

4.web.xml 的配置

<?xml version="1.0" encoding="UTF-8"?>


<web-app version="3.0" 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_3_0.xsd">


<display-name>Archetype Created Web Application</display-name>

评论

发布
暂无评论
SSM整合,kafka教程分享