spring-microservices | Microservices using Spring Boot , Spring Cloud | Microservice library
kandi X-RAY | spring-microservices Summary
Support
Quality
Security
License
Reuse
- Deletes the user with the given id .
- Gets the details of a Course .
- Logs execution .
- Handle method argument not valid .
- Inserts a user .
- Provide default sampler
- Set the field2 .
- Gets the role .
- Set the name .
- Set the maximum allowed value .
spring-microservices Key Features
spring-microservices Examples and Code Snippets
Trending Discussions on spring-microservices
Trending Discussions on spring-microservices
QUESTION
After having followed a tutorial about microserves and OAuth2 in Maven Spring Boot, I got a problem. I want to exclude a request from the authentication, so unauthorized data can be gotten. This only doesn't seem to work in the way I do it. Can someone help me with this?
Tutorial I followed: https://developer.okta.com/blog/2018/02/13/secure-spring-microservices-with-oauth#microservices-architectures-with-spring-boot--spring-cloud
What I tried:
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.requestMatcher(new RequestHeaderRequestMatcher("Authorization"))
.authorizeRequests()
.antMatchers("/**").authenticated()
.and()
.authorizeRequests()
.andMatchers(HttpMethod.GET, "/beers").permitAll();
}
}
I have to authenticate when I try to do the request. How do I solve this?
spring-security-oauth2-autoconfigure: 2.1.1.RELEASE
ANSWER
Answered 2020-Jun-13 at 06:44Firstly, your configuration is the same as the followings . Just removing those unnecessary duplicated authorizeRequests()
and and()
, which make it look more clearly :
http.requestMatcher(new RequestHeaderRequestMatcher("Authorization"))
.authorizeRequests()
.antMatchers("/**").authenticated()
.andMatchers(HttpMethod.GET, "/beers").permitAll();
It means spring security will only handle the requests if it has Authorization
header. Otherwise ,the request will be ignored and no spring security stuff will apply to it.
So if the request has the Authorization
header , it will then start to check the rules (i.e. those matcher things configured by authorizeRequests()
) from the top to the bottom according to the declaration order.Once a rule is matched , the bottom rule will be ignored and will not be checked.
Since your first rule is to match every HTTP request ("/**") which makes all rules below it never execute and does not have any meaning.
On the other hand , if you want spring security totally ignore "/beers" even its request has Authorization
header , you should configure WebSecurity
to ignore it :
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers(HttpMethod.GET, "/beers");
}
QUESTION
I am doing a POC on simple microservices architecture using typical Spring cloud stack but instead of Eureka server, service discovery is to be made using spring-cloud-kubernetes which is not working.
The whole POC is here - https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes
Gateway as a edge server and 2 downstream services- user-service and contact-us-service.
The k8 setup is in k8s folder.
The downstream services have following dependencies:
org.springframework.cloud
spring-cloud-starter-kubernetes
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
application.yml
server:
port: 8100
management:
endpoints:
web:
exposure:
include: '*'
spring:
cloud:
kubernetes:
enabled: true
reload:
enabled: true
eureka:
client:
enabled: false
bootstrap.yml:
spring:
application:
name: user-service
and annotation of @EnableDiscoveryClient
in the main class.
The gateway service has too relevant kubernetes dependencies:
org.springframework.cloud
spring-cloud-starter-kubernetes
org.springframework.cloud
spring-cloud-starter-netflix-ribbon
org.springframework.cloud
spring-cloud-starter-kubernetes-ribbon
application.yml
server:
port: 8050
spring:
application:
name: gateway
cloud:
kubernetes:
enabled: true
reload:
enabled: true
gateway:
discovery:
locator:
lowerCaseServiceId: true
enabled: true
eureka:
client:
enabled: false
logging:
level:
root: DEBUG
org.springframework.gateway: TRACE
org.springframework.cloud.gateway: TRACE
org.springframework.cloud.loadbalancer: TRACE
management:
endpoints:
web:
exposure:
include: '*'
bootstrap.yml
spring:
application:
name: gateway
and annotation of @EnableDiscoveryClient
in the main class.
Please see the deployment and service yaml here - https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes/tree/master/k8s
I am able to get to gateway but it is not routing to downstream service like user-service:
For example - /user-service/users/getPublicMailingAddress
gives Whitable error page
and the logs in gateway shows:
2019-07-07 06:40:30.017 TRACE 1 --- [or-http-epoll-2] o.s.c.g.h.p.RoutePredicateFactory : Pattern "[/my-nginx-nginx-ingress-controller/**]" does not match against value "/user-service/users/getPublicMailingAddress"
ANSWER
Answered 2019-Jul-17 at 10:08Spring Cloud Kubernetes requires access to the Kubernetes API in order to be able to retrieve a list of addresses for pods running for a single service. If you use Kubernetes, you should just execute the following command:
kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default
QUESTION
I'm trying to set up Spring Cloud Config Server with backend repository (filesystem), but the endpoint(http://localhost:8888/licensingservice/default
) returns the following:
{"name":"licensingservice","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}
The Main:
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
The application.yml:
server:
port: 8888
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: file:///Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config
The licensingservice.yml:
tracer.property: "I AM THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform: "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "p0stgr@s"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"
C:\Users\josedavi\Desenvolvimento\WorkSpace\Pessoal\sample-spring-microservices\sample-spring-microservices\config-server\src\main\resources\config
ANSWER
Answered 2019-Feb-07 at 15:27Add the following format in your application.yml
of config service:
[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]
The above format search locations from config
folder, next folder with application
name, application
name and profile
respectively.
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]"
QUESTION
I've createde Eureka server with the replication and now trying to start the client. When I'm trying to start the spring-microservices-eureka-client
, I get the below error. Using Spring Boot Version 2.1.1.RELEASE
. The same error is coming with the Boot Version 2.0.7.RELEASE
and Finchley.SR2
.
2018-12-28 13:52:16.741 INFO 20236 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application UNKNOWN with eureka with status UP
2018-12-28 13:52:16.742 INFO 20236 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1545985336742, current=UP, previous=STARTING]
2018-12-28 13:52:16.743 INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org: registering service...
2018-12-28 13:52:16.749 INFO 20236 --- [ main] ringMicroservicesEurekaClientApplication : Started SpringMicroservicesEurekaClientApplication in 3.335 seconds (JVM running for 4.12)
2018-12-28 13:52:16.752 INFO 20236 --- [ Thread-6] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application UNKNOWN with eureka with status DOWN
2018-12-28 13:52:16.752 WARN 20236 --- [ Thread-6] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1545985336752, current=DOWN, previous=UP]
2018-12-28 13:52:16.756 INFO 20236 --- [ Thread-6] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2018-12-28 13:52:16.788 INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - registration status: 204
2018-12-28 13:52:16.789 INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org: registering service...
2018-12-28 13:52:16.793 INFO 20236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - registration status: 204
2018-12-28 13:52:16.793 INFO 20236 --- [ Thread-6] com.netflix.discovery.DiscoveryClient : Unregistering ...
2018-12-28 13:52:16.799 INFO 20236 --- [ Thread-6] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/841DTN2.corp.abc.org - deregister status: 200
2018-12-28 13:52:16.805 INFO 20236 --- [ Thread-6] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
spring-microservices-eureka-server application.yml
---
spring:
profiles: peer1
server:
port: 8761
eureka:
instance:
hostname: peer1
client:
service-url:
defaultZone: http://peer2:8762/eureka
register-with-eureka: false
fetch-registry: false
---
spring:
profiles: peer2
server:
port: 8762
eureka:
instance:
hostname: peer2
client:
service-url:
defaultZone: http://peer1:8761/eureka
register-with-eureka: false
fetch-registry: false
SpringMicroservicesEurekaServerApplication.java
@EnableEurekaServer
@SpringBootApplication
public class SpringMicroservicesEurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringMicroservicesEurekaServerApplication.class, args);
}
}
pom.mxl
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
com.oreilly.cloud
spring-microservices-eureka-server
0.0.1-SNAPSHOT
spring-microservices-eureka-server
Demo project for Spring Boot
1.8
Greenwich.RC2
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
spring-microservices-eureka-client
SpringMicroservicesEurekaClientApplication.java
@SpringBootApplication
@EnableEurekaClient
public class SpringMicroservicesEurekaClientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringMicroservicesEurekaClientApplication.class, args);
}
}
Reference issue: https://github.com/spring-cloud/spring-cloud-netflix/issues/2099 - This look major issue to me.
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE
com.oreilly.cloud
spring-microservices-eureka-client
0.0.1-SNAPSHOT
spring-microservices-eureka-client
Demo project for Spring Boot
1.8
Greenwich.RC2
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
ANSWER
Answered 2018-Dec-31 at 05:48I was able to solve this issue by adding the web dependency
org.springframework.boot
spring-boot-starter-web
QUESTION
I have a docker image https://github.com/carnellj/spmia-chapter1 which does not find its CMD ./run.sh executable although it is there in the file system.
I was able to run /bin/sh in the container, and I can ls -l:
D:\Dokumente\ws\spring-microservices\spmia-chapter1 (master)
λ docker run -i -t johncarnell/tmx-simple-service:chapter1 /bin/sh
/ # ls -l
total 56
drwxr-xr-x 2 root root 4096 Mar 3 11:20 bin
drwxr-xr-x 5 root root 360 Apr 22 07:10 dev
drwxr-xr-x 1 root root 4096 Apr 22 07:10 etc
drwxr-xr-x 2 root root 4096 Mar 3 11:20 home
drwxr-xr-x 1 root root 4096 Apr 22 06:01 lib
drwxr-xr-x 5 root root 4096 Mar 3 11:20 media
drwxr-xr-x 2 root root 4096 Mar 3 11:20 mnt
dr-xr-xr-x 123 root root 0 Apr 22 07:10 proc
drwx------ 1 root root 4096 Apr 22 07:10 root
drwxr-xr-x 2 root root 4096 Mar 3 11:20 run
-rwxr-xr-x 1 root root 245 Apr 22 06:50 run.sh
drwxr-xr-x 2 root root 4096 Mar 3 11:20 sbin
drwxr-xr-x 2 root root 4096 Mar 3 11:20 srv
dr-xr-xr-x 13 root root 0 Apr 22 07:10 sys
drwxrwxrwt 2 root root 4096 Mar 3 11:20 tmp
drwxr-xr-x 1 root root 4096 Mar 7 01:04 usr
drwxr-xr-x 1 root root 4096 Mar 7 01:04 var
/ # ./run.sh
/bin/sh: ./run.sh: not found
/ # ls run.sh
run.sh
/bin/sh does not find ./run.sh although it is there in the file system, as proven by ls run.sh. Also, cat shows the content of run.sh:
/ # cat run.sh
#!/bin/sh
echo "********************************************************"
echo "Starting simple-service "
echo "********************************************************"
java -jar /usr/local/simple-service/simple-service-0.0.1-SNAPSHOT.jar
When I run vi from sh and copy the content of run.sh into a new file myrun.sh and make myrun.sh executable, I can execute ./myrun.sh and the spring service starts.
What is going on here? Why would sh not see an executable which is there in the filesystem? Executables from PATH or executables which I add manually run fine.
I am running Docker on Windows 10.
ANSWER
Answered 2017-Apr-22 at 08:34OK the reason is, run.sh is created with Windows line endings in the docker image if you check out with automatic lf->crlf conversion. One possible solution is to tell git not to convert line endings.
QUESTION
I am reading this release announcement for Spring Cloud dataflow. https://spring.io/blog/2017/02/22/spring-cloud-data-flow-for-cloud-foundry-1-1-1-maintenance-release-available
I am wondering if we need a minimum version of cloud foundry for successfully running spring cloud data applications.. Given that this stream of work is actually targeted for cloud based environments, i think they should also mention the minimum base Cloud Foundry versions that can support them.
Does this require an inter-process communication that's being made available in latest cloud foundry versions https://www.cloudfoundry.org/meet-new-container-networking-stack-cloud-foundry/ https://content.pivotal.io/blog/building-spring-microservices-with-cloud-foundrys-new-container-networking-stack
I do see the mention of PCF version compatibility for Spring Cloud Tasks http://docs.spring.io/spring-cloud-dataflow-server-cloudfoundry/docs/current-SNAPSHOT/reference/htmlsingle/#_version_compatibility
But i haven't been able to find the Base cloud foundry version that supports the features of Spring Cloud Data Flow in general or per feature compatibility breakdown with Cloud foundry versions. We are running IBM Bluemix in our company and are upgrading to the cf version that supports Deigo architecture (vs the current DEA) - don't know the exact version of CF will that be.
If we know the Spring Cloud Data flow feature compatibility with specific Cloud Foundry versions we can decide our adoption strategy accordingly.
ANSWER
Answered 2017-Mar-01 at 18:34Please refer to PCF vs. OSS CF compatibility matrix from the project site.
This matrix captures the baseline OSS CF release required to run SCDF on the particular PCF versions. You could further dive into respective PCF release-notes to double check other OSS components (eg., CAPI) for more granular compatibility measurements.
Tasks in SCDF, in particular, is GA'd with PCF 1.9; so if you're planning to use it, you'd have to be at least on OSS CF 246 release.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-microservices
You can use spring-microservices like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-microservices component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page