前言:
如今我们对“apache配置minetype”大概比较讲究,小伙伴们都想要分析一些“apache配置minetype”的相关知识。那么小编在网摘上网罗了一些关于“apache配置minetype””的相关知识,希望同学们能喜欢,各位老铁们快快来了解一下吧!目前微服务开发框架基本上都是采用Spring Cloud ,但是由于Eureka已经不再开源,所以在服务注册与发现慢慢都不再采用Eureka了,而是转到阿里的Nacos上了。因为Nacos也支持配置管理,所以配置管理这块也基本采用Nacos了。当然了你也可以使用携程的Apollo,也是很不错的。Nacos都能解决也就不多此一举了。下面主要介绍下Spring Cloud 与Alibaba微服务组件的集成。
集成的各个组件的版本如下
1、Spring Cloud : Hoxton.SR8
2、Spring boot :2.3.2.RELEASE
3、Alibaba Cloud :2.2.3.RELEASE
一、创建maven父依赖
创建自己的父依赖,不直接继承Spring Boot。因为直接继承Spring boot 会带来很多不便,不能集成其他组件了。 创建maven项目test-parent, POM文件如下
<?xml version="1.0" encoding="UTF-8"?><project xmlns="; xmlns:xsi="; xsi:schemaLocation=" ;> <modelVersion>4.0.0</modelVersion> <groupId>com.test.parent</groupId> <artifactId>test-parent</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <description>Spring Cloud Alibaba Spring Boot</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <alibaba.cloud.version>2.2.3.RELEASE</alibaba.cloud.version> <spring.cloud.version>Hoxton.SR8</spring.cloud.version> <spring.boot.version>2.3.2.RELEASE</spring.boot.version> </properties> <dependencies> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring.cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${alibaba.cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring.boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement></project>
二、创建微服务test-user
1、创建服务POM文件如下
<project xmlns="; xmlns:xsi="; xsi:schemaLocation=" ;> <parent> <groupId>com.test.parent</groupId> <artifactId>test-parent</artifactId> <version>1.0.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>test-user</artifactId> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </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>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> </dependencies> <build> <finalName>test-user</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build></project>
2、创建test-user配置文件 bootstrap.yml
server: port: 8081spring: profiles: active: dev application: name: test-user-service cloud: nacos: config: namespace: ${spring.profiles.active} server-addr: 127.0.0.1:8848 extension-configs[0]: data-id: test_user_db.yml group: DEFAULT_GROUP refresh: true extension-configs[1]: data-id: test_user_commons.yml group: DEFAULT_GROUP refresh: true
a、Nacos中添加配置test_user_db.yml的内容如下:
spring: datasource: url: jdbc:mysql://127.0.0.1:3306/test_user?useSSL=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai username: root password: test_user type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver filter: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20mybatis-plus: mapper-locations: classpath:sqlmapper/**/*.xml type-aliases-package: com.test.user.dao.entity configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
b、Nacos中添加配置test_user_commons.yml的内容如下
#nacos 注册发现配置spring: cloud: nacos: discovery: namespace: dev server-addr: 127.0.0.1:8848management: endpoints: web: exposure: include: "*"
到此 Spring Cloud Alibaba Spring boot 微服务集成就全部完成了。下次准备再把Spring Cloud Alibaba String Boot Dubbo 做个集成
标签: #apache配置minetype