taotao-manager-service有关的: dao的整合、service的整合
整合后的结构:
SqlMapConfig.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 | <? 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 > < plugins > <!-- com.github.pagehelper为PageHelper类所在包名 --> < plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库--> < property name="dialect" value="mysql"/> </ plugin > </ plugins > </ configuration > |
db.properties
1 2 3 4 | jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8 jdbc.username=root jdbc.password=123456 |
applicationContext-dao.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <? xml version="1.0" encoding="UTF-8"?> < beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <!-- 数据源 --> <!-- 数据库连接池 --> < context:property-placeholder location="classpath:properties/*.properties"/> < bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> < property name="url" value="${jdbc.url}" /> < property name="username" value="${jdbc.username}" /> < property name="password" value="${jdbc.password}" /> < property name="driverClassName" value="${jdbc.driver}" /> < property name="maxActive" value="10" /> < property name="minIdle" value="5" /> </ bean > <!-- sqlsessionfactory --> <!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --> < bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 数据库连接池 --> < property name="dataSource" ref="dataSource" /> <!-- 加载mybatis的全局配置文件 --> < property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" /> </ bean > < bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> < property name="basePackage" value="com.taotao.mapper" /> </ bean > <!-- mapper扫描器 --> </ beans > |
applicationContext-service.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <? xml version="1.0" encoding="UTF-8"?> < beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> < context:component-scan base-package="com.taotao.service"></ context:component-scan > <!-- 使用dubbo发布服务 --> <!-- 提供方应用信息,用于计算依赖关系。name="taotao-manager"这个名字理论上可以随便命名,但最好要保证唯一,避免跨系统时服务重名变得不可靠--> < dubbo:application name="taotao-manager" /> <!-- IP是安装了zookeeper的虚拟机IP,2181端口是Linux下zookeeper安装包的conf文件里当前配置的端口 --> < dubbo:registry protocol="zookeeper" address="192.168.25.128:2181" /> <!-- 用dubbo协议在20880端口暴露服务,其中的name="dubbo"是固定的,但其中的端口不是固定的,20880只是默认值表示本机 --> < dubbo:protocol name="dubbo" port="20880" /> <!-- 声明需要暴露的服务接口 --> <!-- ref="testServiceImpl"是加了注解@Service的实现类类名,首字母小写后为testServiceImpl得到 --> < dubbo:service interface="com.taotao.service.TestService" ref="testServiceImpl" /> < dubbo:service interface="com.taotao.service.ItemService" ref="itemServiceImpl" /> </ beans > |
如果离线环境报错,则需要本地加上 dubbo.xsd文件
然后在taotao-manager-interface的src/main/java下,新建包com.taotao.service
applicationContext-transaction.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <? xml version="1.0" encoding="UTF-8"?> < beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <!-- 事务管理器 --> <!-- 配置通知 --> <!-- 配置切面 --> <!-- 事务管理器 --> < bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 数据源 --> < property name="dataSource" ref="dataSource" /> </ bean > <!-- 通知 --> < tx:advice id="txAdvice" transaction-manager="transactionManager"> < tx:attributes > <!-- 传播行为 --> <!-- REQUIRED表示,如果当前没有事务则开启事务。如果当前有事务,则执行事务 --> <!-- SUPPORTS表示,如果当前有事务就在当前事务执行。如果当前没有事务,也无所谓 --> < tx:method name="save*" propagation="REQUIRED" /> < tx:method name="insert*" propagation="REQUIRED" /> < tx:method name="add*" propagation="REQUIRED" /> < tx:method name="create*" propagation="REQUIRED" /> < tx:method name="delete*" propagation="REQUIRED" /> < tx:method name="update*" propagation="REQUIRED" /> < tx:method name="find*" propagation="SUPPORTS" read-only="true" /> < tx:method name="select*" propagation="SUPPORTS" read-only="true" /> < tx:method name="get*" propagation="SUPPORTS" read-only="true" /> </ tx:attributes > </ tx:advice > <!-- 切面 --> <!-- 切面作用,表示上面的事务针对什么表达式管理 --> < aop:config > < aop:advisor advice-ref="txAdvice" pointcut="execution(* com.taotao.service.*.*(..))" /> </ aop:config > </ beans > |
log4j.properties
1 2 3 4 5 | log4j.rootLogger=WARN,A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n |
web.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <? xml version="1.0" encoding="UTF-8"?> < web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> < display-name >taotao-manager-service</ display-name > < welcome-file-list > < welcome-file >index.html</ welcome-file > < welcome-file >index.htm</ welcome-file > < welcome-file >index.jsp</ welcome-file > < welcome-file >default.html</ welcome-file > < welcome-file >default.htm</ welcome-file > < welcome-file >default.jsp</ welcome-file > </ welcome-file-list > <!-- 初始化spring容器 --> < context-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:spring/applicationContext-*.xml</ param-value > </ context-param > < listener > < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class > </ listener > </ web-app > |
https://github.com/godmaybelieve
分类:
Spring相关
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理