Spring Boot使用spring-data-jpa配置Mysql多数据源

article/2025/9/30 4:28:05

转载请注明出处 :Spring Boot使用spring-data-jpa配置Mysql多数据源

我们在之前的文章中已经学习了Spring Boot中使用mysql数据库

在单数据源的情况下,Spring Boot的配置非常简单,只需要在application.properties文件中配置连接参数即可。

但是往往随着业务量发展,我们通常会进行数据库拆分或是引入其他数据库,从而我们需要配置多个数据源,下面基于之前的Spring-data-jpa例子分别介绍多数据源的配置方式。

目前有需求是会使用两个mysql的数据源。

注意,本文使用于 Spring Boot 2.0之前的版本,2.0之后的版本有部分区别,可查看文后说明。

记录配置步骤如下:

检查需要的包

如果没有则在pom.xml中补全。

<!-- Use MySQL Connector-J --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency>
<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>

目录结构

目录结构很重要,尤其是多数据源的情况下。

本次结构如图

定义DataSourceConfig

package com.biologic.util;import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;@Configuration
public class MysqlDataSourceConfig {@Bean(name = "primaryDataSource")@Qualifier("primaryDataSource")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSource primaryDataSource() {return DataSourceBuilder.create().build();}@Bean(name = "secondaryDataSource")@Qualifier("secondaryDataSource")@Primary@ConfigurationProperties(prefix = "spring.datasource.secondary")public DataSource secondaryDataSource() {return DataSourceBuilder.create().build();}}

参数配置

对应的application.properties配置如下:


# 通用部分设置
spring.jpa.database=MYSQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect#primary数据库
spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1
spring.datasource.primary.username=root
spring.datasource.primary.password=root
spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver#secondary数据库
spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2
spring.datasource.secondary.username=root
spring.datasource.secondary.password=root
spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver

第一个数据源配置

新增对第一数据源的JPA配置,注意两处注释的地方,用于指定数据源对应的Entity实体和Repository定义位置,用@Primary区分主数据源。

package com.example.demo.mysql.config;import java.util.HashMap;
import java.util.Map;import javax.persistence.EntityManager;
import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef="entityManagerFactoryPrimary",transactionManagerRef="transactionManagerPrimary",basePackages= { "com.example.demo.mysql.reposity.primary" }) //设置Repository所在位置public class MysqlPrimaryConfig {@Autowired @Qualifier("primaryDataSource")private DataSource primaryDataSource;@Primary@Bean(name = "entityManagerPrimary")public EntityManager entityManager(EntityManagerFactoryBuilder builder) {return entityManagerFactoryPrimary(builder).getObject().createEntityManager();}@Primary@Bean(name = "entityManagerFactoryPrimary")public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) {return builder.dataSource(primaryDataSource).properties(getVendorProperties(primaryDataSource)).packages("com.example.demo.mysql.entity.primary") //设置实体类所在位置.persistenceUnit("primaryPersistenceUnit").build();}@Autowiredprivate JpaProperties jpaProperties;private Map<String, String> getVendorProperties(DataSource dataSource) {jpaProperties.setDatabase(Database.MYSQL);Map<String,String> map = new HashMap<>();map.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");map.put("hibernate.hbm2ddl.auto","update");map.put("hibernate.physical_naming_strategy","org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl");jpaProperties.setProperties(map);return  jpaProperties.getHibernateProperties(dataSource);}@Primary@Bean(name = "transactionManagerPrimary")public PlatformTransactionManager transactionManagerPrimary(EntityManagerFactoryBuilder builder) {return new JpaTransactionManager(entityManagerFactoryPrimary(builder).getObject());}}

第二个数据源配置

新增对第二数据源的JPA配置,内容与第一数据源类似,只是修改repository和entity保存的路径,具体如下:

package com.example.demo.mysql.config;import java.util.HashMap;
import java.util.Map;import javax.persistence.EntityManager;
import javax.sql.DataSource;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef="entityManagerFactorySecondary",transactionManagerRef="transactionManagerSecondary",basePackages= { "com.example.demo.mysql.reposity.secondary" }) //设置Repository所在位置
public class MysqlSecondaryConfig {@Autowired @Qualifier("secondaryDataSource")private DataSource secondaryDataSource;@Bean(name = "entityManagerSecondary")public EntityManager entityManager(EntityManagerFactoryBuilder builder) {return entityManagerFactoryPrimary(builder).getObject().createEntityManager();}@Bean(name = "entityManagerFactorySecondary")public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary (EntityManagerFactoryBuilder builder) {return builder.dataSource(secondaryDataSource).properties(getVendorProperties(secondaryDataSource)).packages("com.example.demo.mysql.entity.secondary") //设置实体类所在位置.persistenceUnit("secondaryPersistenceUnit").build();}@Autowiredprivate JpaProperties jpaProperties;private Map<String, String> getVendorProperties(DataSource dataSource) {jpaProperties.setDatabase(Database.MYSQL);Map<String,String> map = new HashMap<>();map.put("hibernate.dialect","org.hibernate.dialect.MySQL5Dialect");map.put("hibernate.hbm2ddl.auto","update");map.put("hibernate.physical_naming_strategy","org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl");jpaProperties.setProperties(map);return  jpaProperties.getHibernateProperties(dataSource);}@Bean(name = "transactionManagerSecondary")public PlatformTransactionManager transactionManagerPrimary(EntityManagerFactoryBuilder builder) {return new JpaTransactionManager(entityManagerFactoryPrimary(builder).getObject());}}

创建实体和Repository接口

完成了以上配置之后,
主数据源的实体位于: com.biologic.entity.mysqlprimary
主数据源的数据访问对象位于:com.biologic.api.repository.mysqlprimary
第二数据源的实体位于: com.biologic.entity.mysqlsecondary
第二数据源的数据访问接口位于:com.biologic.api.repository.mysqlsecondary

分别在这些package下创建各自的实体和数据访问接口

主数据源下,创建User实体和对应的Repository接口

User.java

package com.example.demo.mysql.entity.primary;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;@Entity
public class User {@Id@GeneratedValueprivate Long id;@Column(nullable = false)private String name;@Column(nullable = false)private Integer age;public User(){}public User(String name, Integer age) {this.name = name;this.age = age;}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}}

UserRepository.java

package com.example.demo.mysql.reposity.primary;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;import com.example.demo.mysql.entity.primary.User;@Repository
public interface UserMysqlRepository extends JpaRepository<User, Long> {}

第二数据源下,创建Message实体和对应的Repository接口
Message.java

package com.example.demo.mysql.entity.secondary;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;@Entity
public class Message {@Id@GeneratedValueprivate Long id;@Column(nullable = false)private String name;@Column(nullable = false)private String content;public Message() {}public Message(String name, String content) {this.name = name;this.content = content;}public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}}

MessageRepository.java

package com.example.demo.mysql.reposity.secondary;import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;import com.example.demo.mysql.entity.secondary.Message;@Repository
public interface MessageRepository extends JpaRepository<Message, Long> {}

测试使用

Controller方式

package com.example.demo.api;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import com.example.demo.mysql.entity.primary.User;
import com.example.demo.mysql.entity.secondary.Message;
import com.example.demo.mysql.reposity.primary.UserMysqlRepository;
import com.example.demo.mysql.reposity.secondary.MessageRepository;@RestController
public class HelloWorldController {@Autowiredprivate UserMysqlRepository userMysqlRepository;@Autowiredprivate MessageRepository messageRepository;@RequestMapping("/hello")public int index() {userMysqlRepository.save(new User("aaa", 10));userMysqlRepository.save(new User("bbb", 20));userMysqlRepository.save(new User("ccc", 30));userMysqlRepository.save(new User("ddd", 40));userMysqlRepository.save(new User("eee", 50));System.out.println(userMysqlRepository.findAll().size());messageRepository.save(new Message("o1", "aaaaaaaaaa"));messageRepository.save(new Message("o2", "bbbbbbbbbb"));messageRepository.save(new Message("o3", "cccccccccc"));return userMysqlRepository.findAll().size() + messageRepository.findAll().size();}
}

ApplicationTests方式
测试用例来验证使用这两个针对不同数据源的配置进行数据操作。

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
public class ApplicationTests {@Autowiredprivate UserRepository userRepository;@Autowiredprivate MessageRepository messageRepository;@Testpublic void test() throws Exception {userRepository.save(new User("aaa", 10));userRepository.save(new User("bbb", 20));userRepository.save(new User("ccc", 30));userRepository.save(new User("ddd", 40));userRepository.save(new User("eee", 50));Assert.assertEquals(5, userRepository.findAll().size());messageRepository.save(new Message("o1", "aaaaaaaaaa"));messageRepository.save(new Message("o2", "bbbbbbbbbb"));messageRepository.save(new Message("o3", "cccccccccc"));Assert.assertEquals(3, messageRepository.findAll().size());}}

注意事项:版本问题

主要记录spring boot升级2.0后报的错,即springboot1.*正常,测试版本为1.5.4

不同点一:getVendorProperties调用不同

2.0之前的调用类型为DataSource

 private Map getVendorProperties(DataSource dataSource) {return jpaProperties.getHibernateProperties(dataSource);}

2.0之后的调用类型为HiberateSettings

public Map<String, Object> getVerdorProperties(){return jpaProperties.getHibernateProperties(new HibernateSettings());}

不同点二:数据库注入方式不同
2.0之前为

    @Autowired@Qualifier("primaryDataSource")private DataSource primaryDataSource;@Bean@Primary@Qualifier("primaryDataSource")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSource DataSource1() {return DataSourceBuilder.create().build();}

2.0之后为

    @Bean@Primary@Qualifier("primaryDataSource")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSourceProperties primaryDataSourceProperties(){return new DataSourceProperties();}@Bean@Primary@Qualifier("primaryDataSource")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSource primaryDataSource(){return primaryDataSourceProperties().initializeDataSourceBuilder().build();}@Autowired@Qualifier("primaryDataSource")private DataSource primaryDataSource;

数据库注入方式如果不修改的话报错为

java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName

HibernateSettings类其实就是配置列名生成策略的,如果已经在yml里配置过了,这里直接new 一个空类过去就行了

spring:  datasource:  primary:  url: jdbc:mysql://localhost:3306/company?autoReconnect=true&useUnicode=true  username: root  password: root  secondary:  url: jdbc:mysql://localhost:3306/com1?autoReconnect=true&useUnicode=true  username: root  password: root  jpa:  database: mysql  generate-ddl: true  show-sql: true  hibernate:  ddl-auto: update  naming:  physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy  

Spring Boot 2.1.0参见上文代码,引进了HibernateProperties。
同时,在Spring Boot 2.1.0中默认的mysql-connector-java版本为8.0.13,连接低版本mysql配置上比较繁琐,建议在配置文件中手动指定相应版本,如本文中指定5.1.46这个版本。
runtimeOnly(‘mysql:mysql-connector-java:5.1.46’)

注意事项 : 是否需要exclude自动HibernateJpaAutoConfiguration等

在配置正确的情况下,不需要exclude任何配置即可配置成功。
但是网上很多帖子说需要
配置

spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

或者


这样的配置可能导致报错

Description:Field jpaProperties in com.biologic.util.MysqlPrimaryConfig required a bean of type 'org.springframework.boot.autoconfigure.orm.jpa.JpaProperties' that could not be found.Action:Consider defining a bean of type 'org.springframework.boot.autoconfigure.orm.jpa.JpaProperties' in your configuration.

可能遇到的问题–No bean named ‘entityManagerFactory’ available

2018-12-17 15:01:57.618  WARN 26428 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepository': Cannot create inner bean '(inner bean)#7348e75e' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7348e75e': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available

正常情况下 只要在MysqlPrimaryConfig配置了@Primary参数,就会自动成为entityManagerFactory。
如果报这个错,需要检查是否加了@Primary,@Primary是否在其他配置中重复。
以及MysqlPrimaryConfig是否加了@Configuration的标记,以及整个项目的包扫描情况,确保MysqlPrimaryConfig被扫描到。

没有正确加载配置和扫描包导致的错误还有如下几种报错:

Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).
not managed type
At least one JPA metamodel must be present!

关键时候可以尝试强制加载包, 在启动文件加入

@ComponentScan("com.biologic.entity")

注意事项,mongodb多数据源与mysql多数据源同时配置

项目中同时配置了mongodb和mysql甚至redis,会导致配置加载十分混乱。

导致各种奇怪的异常

Multiple Spring Data modules found, entering strict repository configuration mode

此时 项目会进入严格的参数配置模式,要求每种模式都有具体的指向。
比如

@EnableJpaRepositories(basePackages = "com.acme.repositories.jpa")
@EnableMongoRepositories(basePackages = "com.acme.repositories.mongo")

以及
配置文件中

spring.data.redis.repositories.enabled = false

尤其是 目录结构需要规划好。

可用源码下载

https://download.csdn.net/download/q383965374/10856658

参考链接:
https://www.cnblogs.com/sxdcgaq8080/p/7978205.html

转载请注明出处 :Spring Boot使用spring-data-jpa配置Mysql多数据源


http://chatgpt.dhexx.cn/article/Ijko90vE.shtml

相关文章

SpringBoot 配置 JPA

新建项目 在application.properties配置文件中进行配置&#xff08;或者application.yaml中配置也行&#xff09; spring.datasource.urljdbc:mysql://localhost:3306/ssm?characterEncodingutf8&useSSLfalse&serverTimezoneUTC spring.datasource.usernameroot sp…

Springboot---JPA配置

1.在配置文件中写入数据库信息 application.properties配置如下 spring.datasource.primary.urljdbc:mysql://localhost:3306/test1 spring.datasource.primary.usernameroot spring.datasource.primary.passwordroot spring.datasource.primary.driver-class-namecom.mysql.…

spring-boot-starter-data-jpa 配置多个数据源与jpa实体类继承的问题、分页条件查询

JPA的继承注解一般有四种 MappedSuperclass 这个注解应用的场景是父类不对应任何单独的表&#xff0c;多个子类共用相同的属性。 注意&#xff1a; MappedSuperclass注解使用在父类上面&#xff0c;是用来标识父类的作用 MappedSuperclass标识的类表示其不能映射到数据库表&am…

Springboot多数据源+Jpa配置

随着业务复杂程度的增加&#xff0c;单一数据源越来越不满足具体的业务逻辑以及实现。 这里我用到了MySQL和Presto两种数据源&#xff1a; 多数据源配置GlobalDataSourceConfiguration&#xff1a; Configuration public class GlobalDataSourceConfiguration {Bean(name …

springboot--jpa 配置多数据库

使用spring boot jpa 配置多数据源 由于项目整合 以前的功能 但是以前功能存储的数据库是另一个数据库 这两天搜索了一下 遇见了许多坑 在这里记录一下 首先附上我的项目结构 可能有些乱 忘见谅。 pom.xml(把数据库的依赖引入) <!-- mariadb --><dependen…

Spring Data Jpa 配置多数据源

文章目录 1.配置数据库连接信息2.编写数据源配置类3.编写数据库配置4.目录结构 1.配置数据库连接信息 spring:datasource:db1: # 1.0 Datasourceurl: jdbc:mysql://127.0.0.1:3306/test1?useSSLfalse&serverTimezoneGMT%2b8&characterEncodingutf8&connectTimeo…

springboot2+JPA 配置多数据源(不同类型数据库)

注意&#xff1a;看此篇文章之前&#xff0c;springbootjpa的配置环境应搭建好&#xff0c;不会搭可以自行百度。本文章主要讲述配置JPA多数据源。 1.数据源配置文件 application.properties # 数据源thirded&#xff08;oracle数据库&#xff09; spring.jpa.thirded.databa…

jpa配置(jpa配置连接池)

JPA的实体状态有哪些呢&#xff1f; 该接口拥有众多执行数据查询的接口方法&#xff1a; Object getSingleResult()&#xff1a;执行SELECT查询语句&#xff0c;并返回一个结果&#xff1b; List getResultList() &#xff1a;执行SELECT查询语句&#xff0c;并返回多个结果&…

SpringBoot系列之数据库初始化-jpa配置方式

上一篇博文介绍如何使用spring.datasource来实现项目启动之后的数据库初始化&#xff0c;本文作为数据库初始化的第二篇&#xff0c;将主要介绍一下&#xff0c;如何使用spring.jpa的配置方式来实现相同的效果 I. 项目搭建 1. 依赖 首先搭建一个标准的SpringBoot项目工程&am…

Jpa环境配置及入门(增删改查)

案例&#xff1a;客户的相关操作&#xff08;增删改查&#xff09; 1.分析&#xff1a; 1.搭建环境&#xff1a; 创建maven工程&#xff0c;导入相关坐标&#xff1b; 配置使用jpa的核心配置文件&#xff1b; 位置&#xff1b;需要配置到类路径下叫做 META-INF的文件夹下 命…

PHP多国语言开发:CodeIgniter 2PHP框架中的多国语言,语言包(i18n)库

PHP多国语言开发&#xff1a;CodeIgniter 2PHP框架中的多国语言&#xff0c;语言包&#xff08;i18n&#xff09;多国语言库 引言 我们在CodeIgniter开发中经常会碰到多国语言网站&#xff0c;这里我们就来介绍一种简单有效的多国语言的操作方法。 做什么 语言在地址中是这…

Win 10 添加多国语言

不同用户对电脑系统的语言需求也不一样&#xff0c;出于工作原因需要使用其它语言&#xff0c;比如外国友人需要使用英语&#xff0c;俄罗斯语言等&#xff0c;此时很多用户都以为要下载对应语言版本的系统&#xff0c;然后重新安装系统&#xff0c;其实Win10是支持多国语言的&…

手工编译Flex SDK 多国语言包

项目需要将目前版本提供给其它地区&#xff1a;台湾、日韩等&#xff0c;面临着项目语言的国际化问题。 语言代号&#xff1a; 大陆&#xff1a;zh_CN 台湾&#xff1a;zh_TW 香港&#xff1a;zh_HK … 例如想支持繁体&#xff0c;没有zh_TW语言包怎么办&#xff1f; fl…

DevExpress去除多国语言包

DevExpress作为windows开发中较为强大的第三方组件&#xff0c;能极大的提高编程效率和界面效果。但也要引用它较多的dll文件&#xff0c;它专门有个查看dll程序集依赖的工具&#xff0c;在VS的工具菜单下&#xff1a; 在VS的工具菜单内有"DevExpress Assembly Deploymen…

关于VS编译DevExpress默认产生几个多余的多国语言包的问题解决

关于VS编译DevExpress默认产生几个多余的多国语言包的问题解决 VS15开始对于非系统的Dll都会默认复制到本地&#xff0c;即bin\debug下面&#xff0c;复制dll到本地好处在于发布的时候不用再去寻找相关dll,对于dev这么庞大的组件来说&#xff0c;更是如此&#xff0c;当然&…

php源码添加多国语言包,为win7系统添加多国语言包的方法

现在使用win7系统的人越来越多了&#xff0c;对于一些需求也是有所增长&#xff0c;很多用户希望能够将自己的操作系统安装成英文&#xff0c;法文&#xff0c;德文等语言&#xff0c;尤其是对经常出去外国出处的用户很有好吃&#xff0c;比如要和外国客户沟通交流时能看的懂自…

laravel框架安装多国语言包

laravel的一些提示信息都是默认英文&#xff0c;想更改为中文需要下载语言包&#xff0c;执行以下命令 composer require caouecs/laravel-lang:~3.0 执行完后将vendor中的caouecs中的src中的zh-CN文件夹放到views的lang文件夹中 然后还要更改配置项&#xff0c;将config里面…

window10c语言下载,[下载备用]Windows 10多国语言包和独立语言包下载

微软在上周发布Windows 10 周年更新版本之前&#xff0c;已经更新了微软支持库中的Windows 10多国语言包。 此次更新的Windows 10 多国语言包已经可以支持到Windows 10 Version 1607版本&#xff0c;也就是Windows 10 周年更新版本。 不过完整的多国语言包含有超过100种语言的独…

Android多国语言包

生成中文名称的APP如下&#xff1a; step1. step2. step3. step4. step5. 以上步骤仅仅是添加values-zh-rCN文件夹&#xff0c;在AS的res中是看不到的&#xff0c;即使同步后。 这是因为里面没有内容&#xff0c;只需要把默认的string.xml copy到刚才的文件夹中&#xff0c;将…

android语言包,安卓系统添加多国语言包

虽然Android 从 2.3 开始已经支持50种以上的语言,但是不是每种语言都有字体可以显示。遇到一个新需求, 有客户要求对 hindi  语言的支持。于是上 网找了一些资料,发现网上介绍的大部分是如何替换默认字体,就 是替换./works//data/fonts /DroidSansFallback.ttf,但是替换完…