SpringBoot2.1.9 Mybatis由于@Mapper注解多数据源配置不生效问题

一、场景复现

(1)项目

目录

配置文件

spring:application:name: multi-datasourceprofiles:active: dev1datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/base?autoReconnect=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8username: rootpassword: admin
mybatis:mapper-locations: classpath*:mapper/base/*.xmltype-aliases-package: com.mk.mybatis.multidatasourceconfiguration:map-underscore-to-camel-case: truesys:one-mybatis:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/man?autoReconnect=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8username: rootpassword: adminmybatis:mapper-locations: classpath*:mapper/one/*.xmltype-aliases-package: com.mk.mybatis.multidatasource.one.entityconfiguration:map-underscore-to-camel-case: truetwo-mybatis:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/person?autoReconnect=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8username: rootpassword: adminmybatis:mapper-locations: classpath*:mapper/two/*.xmltype-aliases-package: com.mk.mybatis.multidatasource.two.entityconfiguration:map-underscore-to-camel-case: trueserver:port: 8080

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.9.RELEASE</version><relativePath/></parent><groupId>com.mk.mybatis</groupId><artifactId>multi-datasource</artifactId><version>1.0-SNAPSHOT</version><name>multi-datasource</name><description>MybatisMultiDataSource</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.48</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.0</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.20</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>2.1.9.RELEASE</version></dependency><dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.1.5</version><exclusions><exclusion><groupId>javax.persistence</groupId><artifactId>persistence-api</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.7</version><dependencies><dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.7</version></dependency></dependencies><configuration><!--允许移动生成的文件 --><verbose>true</verbose><!-- 是否覆盖 --><overwrite>true</overwrite><!-- 自动生成的配置 --><configurationFile>generatorConfig1.xml</configurationFile></configuration></plugin></plugins></build>
</project>

继承mybatis生成器生成的dao类

@Mapper
public interface DaseDao extends IBaseDao {
}
@Mapper
public interface ManDao extends IManDao {
}
@Mapper
public interface PersonDao extends IPersonDao {
}

默认mybatis数据源配置

@Configuration
@MapperScan(value = "com.mk.mybatis.multidatasource.base.dao", sqlSessionTemplateRef = "baseSqlSessionTemplate")
public class BaseMybatisConfig {@Primary@Bean@ConfigurationProperties(prefix = "spring.datasource")public DataSourceProperties baseDataSourceProperties() {return new DataSourceProperties();}@Primary@Bean("datasource")public DataSource baseDataSource(@Qualifier("baseDataSourceProperties") DataSourceProperties dataSourceProperties) {DataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().build();return dataSource;}@Primary@Bean@ConfigurationProperties(prefix = "mybatis")public MybatisProperties baseMybatisProperties() {return new MybatisProperties();}@Primary@Beanpublic SqlSessionFactory baseSqlSessionFactory(@Qualifier("datasource") DataSource dataSource,@Qualifier("baseMybatisProperties") MybatisProperties mybatisProperties) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);bean.setMapperLocations(mybatisProperties.resolveMapperLocations());bean.setTypeAliasesPackage(mybatisProperties.getTypeAliasesPackage());bean.setConfigurationProperties(mybatisProperties.getConfigurationProperties());bean.setConfiguration(mybatisProperties.getConfiguration());bean.setConfigLocation(Optional.ofNullable(mybatisProperties.getConfigLocation()).map(location -> {try {ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();return resourceResolver.getResource(location);} catch (Exception var3) {return null;}}).orElse(null));return bean.getObject();}@Primary@Beanpublic DataSourceTransactionManager transactionManager(@Qualifier("datasource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Primary@Beanpublic SqlSessionTemplate baseSqlSessionTemplate(@Qualifier("baseSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}

one mybatis数据源配置

@Configuration
@MapperScan(value = "com.mk.mybatis.multidatasource.one.dao", sqlSessionTemplateRef = "oneSqlSessionTemplate")
@Slf4j
public class OneMybatisConfig {@Bean@ConfigurationProperties(prefix = "sys.one-mybatis.datasource")public DataSourceProperties oneDataSourceProperties() {return new DataSourceProperties();}@Beanpublic DataSource oneDataSource(@Qualifier("oneDataSourceProperties") DataSourceProperties dataSourceProperties) {DataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().build();return dataSource;}@Bean@ConfigurationProperties(prefix = "sys.one-mybatis.mybatis")public MybatisProperties oneMybatisProperties(){return new MybatisProperties();}@Beanpublic SqlSessionFactory oneSqlSessionFactory(@Qualifier("oneDataSource") DataSource dataSource,@Qualifier("oneMybatisProperties")MybatisProperties mybatisProperties)throws Exception{SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);bean.setMapperLocations(mybatisProperties.resolveMapperLocations());bean.setTypeAliasesPackage(mybatisProperties.getTypeAliasesPackage());bean.setConfigurationProperties(mybatisProperties.getConfigurationProperties());bean.setConfiguration(mybatisProperties.getConfiguration());bean.setConfigLocation(Optional.ofNullable(mybatisProperties.getConfigLocation()).map(location->{try {ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();return resourceResolver.getResource(location);} catch (Exception var3) {return null;}}).orElse(null));return bean.getObject();}@Beanpublic DataSourceTransactionManager oneTransactionManager(@Qualifier("oneDataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Beanpublic SqlSessionTemplate oneSqlSessionTemplate(@Qualifier("oneSqlSessionFactory") SqlSessionFactory sqlSessionFactory){return new SqlSessionTemplate(sqlSessionFactory);}
}

two mybatis数据源配置

@Configuration
@MapperScan(value = "com.mk.mybatis.multidatasource.two.dao", sqlSessionTemplateRef = "twoSqlSessionTemplate")
@Slf4j
public class TwoMybatisConfig {@Bean@ConfigurationProperties(prefix = "sys.two-mybatis.datasource")public DataSourceProperties twoDataSourceProperties() {return new DataSourceProperties();}@Beanpublic DataSource twoDataSource(@Qualifier("twoDataSourceProperties") DataSourceProperties dataSourceProperties) {DataSource dataSource = dataSourceProperties.initializeDataSourceBuilder().build();return dataSource;}@Bean@ConfigurationProperties(prefix = "sys.two-mybatis.mybatis")public MybatisProperties twoMybatisProperties() {return new MybatisProperties();}@Beanpublic SqlSessionFactory twoSqlSessionFactory(@Qualifier("twoDataSource") DataSource dataSource,@Qualifier("twoMybatisProperties") MybatisProperties mybatisProperties) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);bean.setMapperLocations(mybatisProperties.resolveMapperLocations());bean.setTypeAliasesPackage(mybatisProperties.getTypeAliasesPackage());bean.setConfigurationProperties(mybatisProperties.getConfigurationProperties());bean.setConfiguration(mybatisProperties.getConfiguration());bean.setConfigLocation(Optional.ofNullable(mybatisProperties.getConfigLocation()).map(location -> {try {ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();return resourceResolver.getResource(location);} catch (Exception var3) {return null;}}).orElse(null));return bean.getObject();}@Beanpublic DataSourceTransactionManager twoTransactionManager(@Qualifier("twoDataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}@Beanpublic SqlSessionTemplate twoSqlSessionTemplate(@Qualifier("twoSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}
}

 

(2)测试类

BaseDao

    @Resourceprivate DaseDao baseDao;@Testpublic void testBaseDao()  {System.out.println(baseDao.selectByPrimaryKey(1));}

输出 

2020-05-04 21:03:21,174 DEBUG [main] 5363 com.mk.mybatis.multidatasource.base.base.dao.IBaseDao.selectByPrimaryKey[143]: ==>  Preparing: select id, `name` from base where id = ? 
2020-05-04 21:03:21,205 DEBUG [main] 5394 com.mk.mybatis.multidatasource.base.base.dao.IBaseDao.selectByPrimaryKey[143]: ==> Parameters: 1(Integer)
2020-05-04 21:03:21,221 DEBUG [main] 5410 com.mk.mybatis.multidatasource.base.base.dao.IBaseDao.selectByPrimaryKey[143]: <==      Total: 0
null

 debug看到的数据源

 

 PersonDao

    @Resourceprivate PersonDao personDao;@Testpublic void testPersonDao() {System.out.println(personDao.selectByPrimaryKey(1));}

输出 

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mk.mybatis.multidatasource.two.dao.PersonDao.selectByPrimaryKeyat org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:61)at org.apache.ibatis.binding.MapperProxy$$Lambda$443/448131210.apply(Unknown Source)at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:61)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:56)at com.sun.proxy.$Proxy67.selectByPrimaryKey(Unknown Source)at com.mk.mybatis.multidatasource.MultiDatasourceApplicationTests.testPersonDao(MultiDatasourceApplicationTests.java:34)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

debug看到的数据源 

 

ManDao

    @Resourceprivate ManDao manDao;@Testpublic void testManDao() {System.out.println(manDao.selectByPrimaryKey(1));}

输出:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mk.mybatis.multidatasource.one.dao.ManDao.selectByPrimaryKeyat org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:61)at org.apache.ibatis.binding.MapperProxy$$Lambda$443/736951628.apply(Unknown Source)at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:61)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:56)at com.sun.proxy.$Proxy68.selectByPrimaryKey(Unknown Source)at com.mk.mybatis.multidatasource.MultiDatasourceApplicationTests.testManDao(MultiDatasourceApplicationTests.java:40)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner.run(ParentRunner.java:363)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

debug看到的数据源 

 

 

(3)分析

从上面的测试结果来看,多数据源配置不生效。

然而去掉PersonDao和ManDao的@Mapper注解,多数据源配置就生效了

PersonDao

//@Mapper
public interface PersonDao extends IPersonDao {
}
2020-05-04 21:26:18,477 DEBUG [main] 4644 com.mk.mybatis.multidatasource.two.base.dao.IPersonDao.selectByPrimaryKey[143]: ==>  Preparing: select id, `name` from person where id = ? 
2020-05-04 21:26:18,497 DEBUG [main] 4664 com.mk.mybatis.multidatasource.two.base.dao.IPersonDao.selectByPrimaryKey[143]: ==> Parameters: 1(Integer)
2020-05-04 21:26:18,506 DEBUG [main] 4673 com.mk.mybatis.multidatasource.two.base.dao.IPersonDao.selectByPrimaryKey[143]: <==      Total: 0
null

ManDao

//@Mapper
public interface ManDao extends IManDao {
}
2020-05-04 21:31:04,470 DEBUG [main] 4413 com.mk.mybatis.multidatasource.one.base.dao.IManDao.selectByPrimaryKey[143]: ==>  Preparing: select id, `name` from man where id = ? 
2020-05-04 21:31:04,499 DEBUG [main] 4442 com.mk.mybatis.multidatasource.one.base.dao.IManDao.selectByPrimaryKey[143]: ==> Parameters: 1(Integer)
2020-05-04 21:31:04,513 DEBUG [main] 4456 com.mk.mybatis.multidatasource.one.base.dao.IManDao.selectByPrimaryKey[143]: <==      Total: 0
null

 

二、原由

由于使用了tk.mybatis的包,默认自动全包扫描@Mapper注解。tk.mybatis扫描生成的Mapper比其他自定义配置的bean生成对应的Mapper对象快,而自定义的mybatis@MapperScan后扫描,Dao Bean已经生成了,无法再指定数据源进行注入了。

 

三、解决方案

(1)去掉tk.mybatis

        <dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.1.5</version><exclusions><exclusion><groupId>javax.persistence</groupId><artifactId>persistence-api</artifactId></exclusion></exclusions></dependency>

(2)不加@Mapper注解

//@Mapper
public interface PersonDao extends IPersonDao {
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/322586.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用Windows兼容包简化向.NET Core的迁移

从.NET迁移到.NET Core的一个主要原因&#xff0c;在于后者具备在Linux上运行的能力。但是对于大型企业应用&#xff0c;不可能实现一步迁移到位。由此&#xff0c;Microsoft推荐采用一种逐步迁移做法&#xff1a;第一步&#xff0c;迁移到ASP.NET Core&#xff08;依然使用.NE…

springboot使用xml配置mybatis

前面用注解配置了mybatis&#xff0c;非常的简单&#xff0c;但是在写动态sql语句的时候会非常的麻烦&#xff0c;所以这边我们用xml来重新配置一下 在resource目录下新建 SqlMapConfig.xml 主配置文件 <?xml version"1.0" encoding"UTF-8" ?> &…

SpringBoot2.1.9 Mybatis多数据源配置

一、配置文件 目录 application.yaml spring:application:name: multi-datasourceprofiles:active: devdatasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/base?autoReconnecttrue&ze…

自动类型安全的REST .NET标准库refit

在SCOTT HANSELMAN 博客上看到一个好东西《Exploring refit, an automatic type-safe REST library for .NET Standard》&#xff0c;他推荐了一个.NET标准1.4 的自动类型安全的REST库refit。 refit 类似于Java的Retrofit&#xff0c;是一套RESTful架构的.NET客户端实现&#x…

Visual Studio的语言服务器协议

语言服务器协议&#xff08;LSP&#xff09;是Visual Studio Code的一个重要组件。语言服务器实际上是单独运行的编译器或分析器&#xff0c;它负责处理各种任务&#xff0c;如编译器错误报告、文本悬浮、代码自动完成&#xff08;也就是IntelliSense&#xff09;等。语言服务器…

C#和NewSQL更配 —— TiDB入门

一、背景在上一篇尝试CockroachDB&#xff08;传送门在此&#xff1a;http://www.cnblogs.com/Zachary-Fan/p/cockroachdb_net_csharp.html&#xff09;的过程中&#xff0c;发现如果从常规的RDBMS迁移过去几乎是不太可能的事情&#xff0c;所以掉头开始调研一下也是这2年比较火…

Mysql调优你不知道这几点,就太可惜了

转载自 Mysql调优你不知道这几点&#xff0c;就太可惜了 一、Mysql的逻辑分层 Mysql分为&#xff1a;连接层、服务层、引擎层、存储层。 当客户端向服务端发起操作请求的时候&#xff0c;执行过程是这样的&#xff1a; 1、客户端端与Mysql服务端的连接层建立连接&#xff…

Unity/DotNetty中集成Lidgren实现可靠UDP

lidgren有几个优点&#xff1a;分channel&#xff0c;每个channel都有单独的消息队列&#xff0c;不互相影响。每个消息可以单独选择使用可靠/不可靠传输。支持内网穿透自带加密算法。前端Unity&#xff1a;先贴一张前端使用的网络框架图&#xff1a;Lidgren的Github地址&#…

欢乐纪中A组周六赛【2019.4.13】

前言 做A组被虐好惨 成绩 RankRankRank是有算别人的 RankRankRankPersonPersonPersonScoreScoreScoreAAABBBCCC222巨佬WHF巨佬WHF巨佬WHF140140140404040100100100000222巨佬ZZY巨佬ZZY巨佬ZZY140140140404040100100100000555巨佬HJW巨佬HJW巨佬HJW10010010010010010000000014…

面试官问:如果MySQL引起CPU消耗过大,你会怎么优化

转载自 面试官问&#xff1a;如果MySQL引起CPU消耗过大&#xff0c;你会怎么优化 谁在消耗cpu? 用户系统IO等待软硬中断空闲 祸首是谁&#xff1f; 用户 用户空间CPU消耗&#xff0c;各种逻辑运算 正在进行大量tps 函数/排序/类型转化/逻辑IO访问… 用户空间消耗大量cpu&…

【译】使用Jwt身份认证保护 Asp.Net Core Web Api

原文出自Rui Figueiredo的博客&#xff0c;原文链接《Secure a Web Api in ASP.NET Core》摘要&#xff1a;这篇文章阐述了如何使用 Json Web Token (Jwt)方式 来配置身份验证中间件。这种方式十分适合移动App 后端等不使用cookie的后端程序。网络上有许多资源可以教你如何保护…

禁用Cookie后,Session怎么样使用

转载自 禁用Cookie后&#xff0c;Session怎么样使用 在上篇中更多的是在分析通过Session Cookie这一方式&#xff0c;在每次请求时都将 sessionId以Cookie的形式发到服务端&#xff0c;来保持一致。这也是许多人印象中的 Session在浏览器关闭之后就失效这一说法的来源。 其…

ASP.NET MVC使用Oauth2.0实现身份验证

随着软件的不断发展&#xff0c;出现了更多的身份验证使用场景&#xff0c;除了典型的服务器与客户端之间的身份验证外还有&#xff0c;如服务与服务之间的(如微服务架构)、服务器与多种客户端的(如PC、移动、Web等)&#xff0c;甚至还有需要以服务的形式开放给第三方的&#x…

Spring Boot API 接口文档 Swagger 入门

转载自 芋道 Spring Boot API 接口文档 Swagger 入门 摘要: 原创出处 http://www.iocoder.cn/Spring-Boot/Swagger/ 「芋道源码」欢迎转载&#xff0c;保留摘要&#xff0c;谢谢&#xff01; 本文在提供完整代码示例&#xff0c;可见 https://github.com/YunaiV/SpringBoot-Lab…

ICanPay 统一支付网关

https://github.com/hiihellox10/ICanPay 统一支付网关。对原代码优化。支持NET46和NETSTANDARD2_0。支持支付宝&#xff0c;微信&#xff0c;银联支付渠道通过Web&#xff0c;App&#xff0c;Wap&#xff0c;QRCode方式支付。简化订单的创建、查询、退款跟接收网关返回的支付通…

使用 dotnet core 和 Azure PaaS服务进行devOps开发(Web API 实例)

引子这一篇文章将用一个完整的实例&#xff0c;给大家介绍如何基于dotnet core&#xff08;微软.NET的最新版本&#xff0c;支持跨平台&#xff0c;跨设备的应用开发&#xff0c;详情请参考 https://www.microsoft.com/net 开发一个Web API Service&#xff0c;并且利用Azure的…

如何基于Canal 和 Kafka,实现 MySQL 的 Binlog 近实时同步

转载自 如何基于Canal 和 Kafka&#xff0c;实现 MySQL 的 Binlog 近实时同步 近段时间&#xff0c;业务系统架构基本完备&#xff0c;数据层面的建设比较薄弱&#xff0c;因为笔者目前工作重心在于搭建一个小型的数据平台。优先级比较高的一个任务就是需要近实时同步业务系统…

采用Opserver来监控你的ASP.NET项目系列(二、监控SQL Server与Asp.Net项目)

前言之前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也可以看看.ASP.NET Core之跨平台的实时性能监控ASP.NET Core之跨平台的实时性能监控(2.健康检查)今天我们主要来介绍一下,如何使用Opserver监控我们的SQL Server 和ASP.NET项目的异常监控监控效果如下:SQL Server的…

Spring Boot 参数校验 Validation 入门

转载自 芋道 Spring Boot 参数校验 Validation 入门 本文在提供完整代码示例&#xff0c;可见 https://github.com/YunaiV/SpringBoot-Labs 的 lab-22 目录。 原创不易&#xff0c;给点个 Star 嘿&#xff0c;一起冲鸭&#xff01; 1. 概述 在想标题的时候&#xff0c;到底应该…

Orchard Core一分钟搭建ASP.NET Core CMS

Orchard Core 是Orchard CMS的ASP.NET Core版本。Orchard Core是全新一代的ASP.NET Core CMS。官方文档介绍&#xff1a;http://orchardcore.readthedocs.io/en/latest/GitHub: https://github.com/OrchardCMS/OrchardCore下面快速开始搭建CMS新建项目打开VS2017 新建一个CMSWe…