MicroServices with Spring: Difference between revisions
From My Limbic Wiki
No edit summary |
|||
Line 86: | Line 86: | ||
! scope="row"| Main | ! scope="row"| Main | ||
| | | | ||
* com.microservices. | * com.microservices.common | ||
@SpringBootApplication | |||
'''@EnableEurekaClient''' | |||
* com.microservices.common.'''security''' | |||
'''@Value("${security.jwt.uri:/auth/**}")''' | |||
'''@Value("${security.jwt.header:Authorization}")''' | |||
'''@Value("${security.jwt.prefix:Bearer }")''' | |||
'''@Value("${security.jwt.expiration:#{24*60*60}}")''' | |||
'''@Value("${security.jwt.secret:JwtSecretKey}")''' | |||
| | | | ||
* com.microservices. | * com.microservices.auth | ||
@SpringBootApplication | |||
'''@EnableEurekaClient''' | |||
* com.microservices.common.'''security''' | |||
'''@EnableWebSecurity''' | |||
'''@Autowired''' | |||
private UserDetailsService userDetailsService; | |||
'''@Autowired''' | |||
private JwtConfig jwtConfig; #'''from commons''' | |||
|- | |- | ||
! scope="row"| Pom.xml | ! scope="row"| Pom.xml | ||
| | | | ||
* Dependencies | * Dependencies | ||
spring-boot : web, test & devtools | |||
| | | | ||
* Dependencies | * Dependencies | ||
spring-cloud-starter-netflix-eureka-client | |||
spring-boot : web, test, devtools & Security | |||
io.jsonwebtoken: jjwt | |||
com.microservices.common: SpringEurekaCommon | |||
|- | |- | ||
! scope="row"| Properties | ! scope="row"| Properties | ||
| | | | ||
spring.application.'''name'''=common-service | |||
server.'''port'''=9200 | |||
eureka.'''client.service-url.default-zone'''=http://localhost:8761/eureka | |||
| | | | ||
spring.application.'''name'''=auth-service | |||
server.'''port'''=9100 | |||
eureka.'''client.service-url.default-zone'''=http://localhost:8761/eureka | |||
|- | |- | ||
|} | |} |
Revision as of 00:32, 21 September 2019
Vulgarization
Specificities in a Spring aborescence
Eureka
Is the registration service, all services will connect to the same adress: http://localhost:9000 for example
Fichiers | Server | Zuul | Image & Gallery |
---|---|---|---|
Main |
@SpringBootApplication @EnableEurekaServer // Enable eureka server |
@SpringBootApplication @EnableEurekaClient @EnableZuulProxy |
@SpringBootApplication @EnableEurekaClient
@RestController @RequestMapping("/") @Autowired private Environment env;
|
Pom.xml |
spring-cloud-starter-netflix-eureka-server spring-boot : web, test & devtools |
groupId - org.springframework.cloud spring-cloud-starter-netflix-eureka-client spring-cloud-starter-netflix-zuul groupId - com.microservices.common SpringEurekaCommon spring-boot : web, test, devtools & security |
spring-cloud-starter-netflix-eureka-client spring-boot : web, test & devtools |
Properties |
spring.application.name=eureka-server server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false |
server.port=8762 spring.application.name=zuul-server eureka.client.service-url.default-zone=http://localhost:8761/eureka/ #zuul.prefix=/api
zuul.ignored-services=*
zuul.routes.gallery-service.path=/gallery/** zuul.routes.gallery-service.service-id=gallery-service zuul.routes.auth-service.path=/auth/** zuul.routes.auth-service.service-id=AUTH-SERVICE$
zuul.routes.auth-service.strip-prefix=false zuul.routes.auth-service.sensitive-headers=Cookie,Set-Cookie #Exclude authorization from sensitive headers |
spring.application.name=image-service server.port=8200 eureka.client.service-url.default-zone=http://localhost:8761/eureka |
Fichiers | Common | Auth |
---|---|---|
Main |
@SpringBootApplication @EnableEurekaClient
@Value("${security.jwt.uri:/auth/**}") @Value("${security.jwt.header:Authorization}") @Value("${security.jwt.prefix:Bearer }") @Value("${security.jwt.expiration:#{24*60*60}}") @Value("${security.jwt.secret:JwtSecretKey}") |
@SpringBootApplication @EnableEurekaClient
@EnableWebSecurity @Autowired private UserDetailsService userDetailsService; @Autowired private JwtConfig jwtConfig; #from commons |
Pom.xml |
spring-boot : web, test & devtools |
spring-cloud-starter-netflix-eureka-client spring-boot : web, test, devtools & Security io.jsonwebtoken: jjwt com.microservices.common: SpringEurekaCommon |
Properties |
spring.application.name=common-service server.port=9200 eureka.client.service-url.default-zone=http://localhost:8761/eureka |
spring.application.name=auth-service server.port=9100 eureka.client.service-url.default-zone=http://localhost:8761/eureka |