MicroServices with Spring: Difference between revisions
From My Limbic Wiki
(→Eureka) |
|||
Line 1: | Line 1: | ||
=Vulgarization= | =Vulgarization= | ||
===Eureka=== | ===Eureka=== | ||
Is the registration service, all services will connect to the same adress: http://localhost:9000 for example | Is the registration service, all services will connect to the same adress: http://localhost:9000 for example | ||
Line 51: | Line 50: | ||
return new JwtConfig(); | return new JwtConfig(); | ||
} | } | ||
| | |||
* Dependencies | |||
spring-'''cloud'''-starter-'''netflix-eureka-client''' | |||
spring-'''cloud'''-starter-'''netflix-zuul''' | |||
'''o.jsonwebtoken: jjwt''' | |||
'''com.microservices.common: SpringEurekaCommon''' | |||
spring-boot : web, test, devtools & security | |||
com.sun.xml.bind: jaxb-'''core,api,impl''' | |||
* dependencyManagement | |||
org.springframework.'''cloud''': spring-'''cloud-dependencies''' | |||
* Repositories | |||
https://repo.spring.io/'''milestone''' | |||
| | | | ||
server.'''port'''=8762 | server.'''port'''=8762 | ||
Line 66: | Line 77: | ||
zuul.routes.'''auth-service.strip-prefix'''=false | zuul.routes.'''auth-service.strip-prefix'''=false | ||
zuul.routes.'''auth-service.sensitive-headers'''=Cookie,Set-Cookie #Exclude authorization from sensitive headers | zuul.routes.'''auth-service.sensitive-headers'''=Cookie,Set-Cookie #Exclude authorization from sensitive headers | ||
|- | |- | ||
! scope="row"| Image | ! scope="row"| Image |
Revision as of 21:40, 21 September 2019
Vulgarization
Eureka
Is the registration service, all services will connect to the same adress: http://localhost:9000 for example
/ | Main | Pom.xml | Properties | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Server |
@SpringBootApplication @EnableEurekaServer // Enable eureka server |
spring-cloud-starter-netflix-eureka-server spring-boot : web, test & devtools com.sun.xml.bind: jaxb-core,api,impl
org.springframework.cloud: spring-cloud-dependencies
https://repo.spring.io/milestone |
spring.application.name=eureka-server server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false | ||||||||||||
Zuul |
@SpringBootApplication @EnableEurekaClient @EnableZuulProxy
@Component
//import com.eureka.common.security.JwtConfig; private final JwtConfig jwtConfig;
@EnableWebSecurity @Autowired //import com.eureka.common.security.JwtConfig; private JwtConfig jwtConfig; @Bean public JwtConfig jwtConfig() { return new JwtConfig(); } |
spring-cloud-starter-netflix-eureka-client spring-cloud-starter-netflix-zuul o.jsonwebtoken: jjwt com.microservices.common: SpringEurekaCommon spring-boot : web, test, devtools & security com.sun.xml.bind: jaxb-core,api,impl
org.springframework.cloud: spring-cloud-dependencies
https://repo.spring.io/milestone |
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 | ||||||||||||
Image |
@SpringBootApplication @EnableEurekaClient
@RestController @RequestMapping("/") @Autowired private Environment env;
|
spring-cloud-starter-netflix-eureka-client spring-boot : web, test & devtools org.springframework.cloud: spring-cloud-starter-sleuth
org.springframework.cloud: spring-cloud-dependencies
https://repo.spring.io/milestone |
spring.application.name=image-service server.port=8200 eureka.client.service-url.default-zone=http://localhost:8761/eureka |
Gallery | Common |
@SpringBootApplication @EnableEurekaClient
@Getter @ToString @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}")
|
spring-cloud-starter-netflix-eureka-client org.projectlombok: lombok spring-boot : web, test & devtools
org.springframework.cloud: spring-cloud-dependencies
https://repo.spring.io/milestone |
spring.application.name=common-service server.port=9200 eureka.client.service-url.default-zone=http://localhost:8761/eureka |
Auth |
@SpringBootApplication @EnableEurekaClient
@EnableWebSecurity @Autowired private UserDetailsService userDetailsService; @Autowired //import com.eureka.common.security.JwtConfig; private JwtConfig jwtConfig; @Bean public JwtConfig jwtConfig() { return new JwtConfig(); } @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); }
@Service @Autowired private BCryptPasswordEncoder encoder; @Override public UserDetails |
spring-cloud-starter-netflix-eureka-client spring-boot : web, test, devtools & Security io.jsonwebtoken: jjwt com.microservices.common: SpringEurekaCommon com.sun.xml.bind: jaxb-core,api,impl
org.springframework.cloud: spring-cloud-dependencies
https://repo.spring.io/milestone |
spring.application.name=auth-service server.port=9100 eureka.client.service-url.default-zone=http://localhost:8761/eureka |