【修改】使用Git代替配置中心的本地配置,加入spring cloud bus

This commit is contained in:
wangiegie@gmail.com 2017-10-19 09:43:23 +08:00
parent d451f2d07d
commit cafe839d91
9 changed files with 64 additions and 28 deletions

View File

@ -26,6 +26,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>

View File

@ -4,13 +4,20 @@ server:
spring:
application:
name: pig-config-server
profiles:
active: native
index: 1
cloud:
config:
server:
native:
search-locations: classpath:/config
git:
uri: https://github.com/jieblog/pig-config.git
bus:
trace:
enabled: true
rabbitmq:
port: 5672
host: localhost
username: guest
password: guest
eureka:
instance:
@ -18,3 +25,7 @@ eureka:
client:
serviceUrl:
defaultZone: http://eureka.didispace.com/eureka/
#关闭安全校验
management:
security:
enabled: false

View File

@ -1,12 +0,0 @@
zuul:
ignoredServices: '*'
host:
connect-timeout-millis: 20000
socket-timeout-millis: 20000
routes:
auth-service:
path: /auth/**
serviceId: pig-service-auth
server:
port: 1000

View File

@ -1,10 +0,0 @@
server:
port: 3000
jwt:
header: Authorization
secret: mySecret
expiration: 604800
token:
header: "Bearer "

View File

@ -34,6 +34,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@ -1,12 +1,23 @@
spring:
application:
name: pig-gateway
index: 3
cloud:
config:
fail-fast: true
discovery:
service-id: pig-config-server
enabled: true
profile: dev
label: master
bus:
trace:
enabled: true
rabbitmq:
port: 5672
host: localhost
username: guest
password: guest
eureka:
instance:
@ -14,3 +25,8 @@ eureka:
client:
serviceUrl:
defaultZone: http://eureka.didispace.com/eureka/
#关闭安全校验
management:
security:
enabled: false

View File

@ -39,6 +39,10 @@
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
</dependencies>

View File

@ -3,6 +3,7 @@ package com.github.pig.auth.controller;
import com.github.pig.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
@ -16,6 +17,7 @@ import javax.servlet.http.HttpServletRequest;
* @date 2017/10/13
*/
@RestController
@RefreshScope
public class AuthController {
@Value("${jwt.token.header}")
private String tokenHeader;
@ -55,8 +57,8 @@ public class AuthController {
}
@RequestMapping(value = "user", method = RequestMethod.GET)
public ResponseEntity<?> getUserInfo(String token) throws Exception {
public String getUserInfo(String token) throws Exception {
String username = authService.getUserNameByToken(token);
return ResponseEntity.ok(username);
return tokenHeader;
}
}

View File

@ -1,12 +1,24 @@
spring:
application:
name: pig-service-auth
index: 2
cloud:
config:
fail-fast: true
discovery:
service-id: pig-config-server
enabled: true
profile: dev
label: master
bus:
trace:
enabled: true
rabbitmq:
port: 5672
host: localhost
username: guest
password: guest
eureka:
instance:
@ -14,3 +26,8 @@ eureka:
client:
serviceUrl:
defaultZone: http://eureka.didispace.com/eureka/
#关闭安全校验
management:
security:
enabled: false