Skip to content

Commit e855152

Browse files
committed
add config server
1 parent 8beca36 commit e855152

File tree

8 files changed

+100
-13
lines changed

8 files changed

+100
-13
lines changed

config-server/src/main/java/com/newtouch/cloud/demo/config/ConfigApplication.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6+
import org.springframework.cloud.config.server.EnableConfigServer;
57

68
@SpringBootApplication
9+
@EnableDiscoveryClient
10+
@EnableConfigServer
711
public class ConfigApplication {
812

913
public static void main(String[] args) {

config-server/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
spring:
2+
application:
3+
name: config-server
4+
cloud:
5+
config:
6+
server:
7+
accept-empty: false
8+
profiles:
9+
active: native
10+
eureka:
11+
instance:
12+
prefer-ip-address: true
13+
hostname: ${spring.application.name}
14+
client:
15+
serviceUrl:
16+
defaultZone: http://service-eureka:8090/eureka/
17+
server:
18+
port: 8888
19+
20+
---
21+
spring:
22+
profiles: git
23+
cloud:
24+
config:
25+
server:
26+
git:
27+
uri: https://github.com/LikeSimple/spring-cloud-config
28+
refresh-rate: 15 # 默认为0,即每次请求都刷新远程信息;否则为指定多久后才刷新
29+
default-label: master # 指定默认版本,可以是commit id, tag, branch name
30+
search-paths: repos, {application}/{profile} # 指定搜索子路径以及搜索格式
31+
timeout: 5
32+
# force-pull: true
33+
# deleteUntrackedBranches: true
34+
# clone-on-start: true
35+
# 模板形式
36+
# repos:
37+
# development:
38+
# pattern:
39+
# - '*/development'
40+
# - '*/staging'
41+
# cloneOnStart: true
42+
# uri: https://github.com/development/config-repo
43+
# username: trolley
44+
# password: strongpassword
45+
# 或者也可以使用ssh形式,会使用~/.ssh/下的配置 ,只支持rsa形式,Gti服务器应在known_hosts文件中,HTTPS PROXY则配置在~/.git/config中或者使用启动参数-Dhttps.proxyHost and -Dhttps.proxyPort
46+
---
47+
spring:
48+
profiles: local
49+
cloud:
50+
config:
51+
server:
52+
git:
53+
uri: file://${user.home}/develop/config-repo # 当URI以file开头,则直接读取本地clone目录,主要用于测试,如果在生产环境需要以共享目录形式给所有的配置服务器挂载;该目录为默认搜索
54+
refresh-rate: 15 # 默认为0,即每次请求都刷新远程信息;否则为指定多久后才刷新
55+
default-label: master # 指定默认版本,可以是commit id, tag, branch name
56+
search-paths: repos* # 子目录搜索,支持目录通配符
57+
timeout: 5
58+
59+
---
60+
spring:
61+
profiles: native
62+
cloud:
63+
config:
64+
server:
65+
native:
66+
search-locations: classpath:/config, file:./{application}/{profile}/{label}
67+
---
68+
spring:
69+
profiles: vault
70+
cloud:
71+
config:
72+
server:
73+
vault:
74+
host: 127.0.0.1
75+
port: 8200
76+
scheme: http
77+
backend: secret
78+
default-key: application
79+
profile-separator: ","
80+
kv-version: 2 # For vault version >= 0.10.0
81+
skip-ssl-validation: false
82+
timeout: 5
83+
namespace: null

service/auth/src/main/resources/application.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ spring:
2424
baseline-on-migrate: true
2525
server:
2626
port: 9999
27-
eureka:
27+
eureka: # 注册中心
2828
instance:
2929
prefer-ip-address: true
3030
hostname: ${spring.application.name}
3131
client:
3232
serviceUrl:
33-
defaultZone: http://service-eureka:8090/eureka/
34-
33+
defaultZone: http://service-eureka:8090/eureka/

service/auth/src/main/resources/bootstrap.yml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.newtouch.cloud.demo.organization.service;
22

3-
import com.newtouch.cloud.demo.organization.controller.vo.UserDetails;
4-
5-
63
public interface OrganizationService {
74

8-
UserDetails getUserDetails(String username);
5+
96

107
}

service/organization/src/test/java/OrganizationApplicationTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import com.newtouch.cloud.demo.organization.OrganizationApplication;
22
import com.newtouch.cloud.demo.organization.persistence.mapper.CorporationMapper;
3+
import org.jetbrains.annotations.NotNull;
34
import org.junit.ClassRule;
45
import org.junit.Test;
56
import org.junit.runner.RunWith;
@@ -24,20 +25,23 @@ public class OrganizationApplicationTests {
2425
private CorporationMapper corporationMapper;
2526

2627
@ClassRule
27-
public static MySQLContainer db = new MySQLContainer("mysql:5.7").withDatabaseName("organization");
28+
private static MySQLContainer db = new MySQLContainer("mysql:5.7.22");
29+
2830

2931
@ClassRule
3032
public static GenericContainer redis = new GenericContainer("redis:4.0.12-alpine")
3133
.withExposedPorts(6379);
3234

3335
@ClassRule
3436
public static GenericContainer rabbitMq = new GenericContainer("rabbitmq:3.7.7-management-alpine")
35-
.withExposedPorts(5672);
37+
.withExposedPorts(5672)
38+
.withEnv("RABBITMQ_DEFAULT_USER","rabbit")
39+
.withEnv("RABBITMQ_DEFAULT_PASS", "123456");
3640

3741
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
3842

3943
@Override
40-
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
44+
public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) {
4145
TestPropertyValues.of(
4246
"spring.redis.port=" + redis.getFirstMappedPort(),
4347
"spring.rabbitmq.port=" + rabbitMq.getFirstMappedPort()

service/organization/src/test/resources/application.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ spring:
1313
datasource:
1414
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
1515
url: jdbc:tc:mysql://hostname:3306/dbname?TC_INITSCRIPT=init_db.sql
16-
# username: root
17-
# password: 1234
16+
rabbitmq:
17+
username: rabbit
18+
password: 123456
1819

1920
eureka:
2021
client:

0 commit comments

Comments
 (0)