I am working on a microservice project and implementing the Config Server using GitHub.
I created following files on GitHub-
Each file has the same configuration code (the common configuration for microservices) with different names-
spring:
application:
name: Config-default
eureka:
instance:
prefer-ip-address: true
client:
fetch-registry: true #true by default
register-with-eureka: true #true by default
service-url:
defaultZone: http://localhost:8761/eureka #url of the eureka server, registers with this url
I use the #EnableConfigServer annotation for the configuration server.
In the application.yml for the Configuration Server Microservice I add-
server:
port: 8089
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: <github repository url>
clone-on-start: true
For the client microservices I added following dependency to pom.xml-
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
In the application.yml for the clients I add the configuration-
spring:
application:
name: USER-SERVICE #changes the name of application from UNKNOWN to UserService
config:
import: optional:configserver:http://localhost:8089
profiles:
active: prod
Problem- When I try to run my configuration server microservice I get the following error message-
***************************
APPLICATION FAILED TO START
***************************
Description:
Invalid config server configuration.
Action:
If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
Can somebody please help me find out the problem, why the URL is not detected.
Related
I've a spring boot application (2.5.6) with a dependency on springdoc-openapi.
However, launching swagger-ui (http://localhost:8080/v1/swagger-ui/index.html) doesn't work.
The debug logs are indicating that index.html is not present.
What could be the reason that index.html is not found ?
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
application.yaml
springdoc:
swagger-ui:
tagsSorter: alpha
operations-sorter: alpha
doc-expansion: none
disable-swagger-default-url: true
logging:
level:
root: DEBUG
server:
port: 8080
spring:
application:
name: fe-applic-app
api-version: "v1"
I found the cause of the problem. The context-path was not set in application.yaml.
http://localhost:8080/v1/swagger-ui/index.html
After adding servlet : context-path, swagger-ui is rendered
server:
port: 8080
servlet:
context-path: "/${spring.application.api-version}"
Try swagger-ui.html instead of swagger-ui/index.html. In 60% of the cases swagger-ui.html redirects to its real location.
http://localhost:8080/v1/swagger-ui.html
http://localhost:8080/v3/swagger-ui.html
add this to your configs:
#Configuration
public class WebAppConfig extends WebMvcConfigurationSupport
{
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/4.14.3/");
}
see source
and static-resources
I am trying to enable the actuator on an existing Spring Boot 2 application, which I thought would be straightforward as I have done few times for the application I created from scratch. However, somehow tomcat (as default server) not startup with the actuator port configured in the properties, when the application starts.
Here are snippets of the config and pom
server:
port: 8085
management:
port: 9085
<spring-boot.version>2.3.5.RELEASE</spring-boot.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
In the log of application startup, I can see the server port has been bound to the application but didn't see the actuator one specified in the properties.
18:32:08.435 [main] INFO o.a.c.h.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8085"]
18:32:08.524 [main] INFO o.s.b.w.e.t.TomcatWebServer - Tomcat started on port(s): 8085 (http) with context path ''
I would expect to see a port binding like the log below right after the one above.
2021-01-20 17:01:35.636 INFO 20044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9085 (http)
I have checked the port has not been used by any other application. Did I miss anything else?
From your posting info, you should add some setting to enable endpoints. I give a sample. please try. By another word, management.port is used in spring boot 1.x.
In simple way, you just enable all endpoints and expose all. for security reason, you should make management.endpoints.enabled-by-default to false. then enable endpoint you want to expose.
management:
server:
port: 9085
endpoints:
enabled-by-default: true
web:
# base-path: /mgmt # you can change /actuator to another name
exposure:
include: "*"
# endpoint:
# refresh:
# enabled: true
# loggers:
# enabled: true
# env:
# enabled: true
I am trying to access the spring cloud config server but it is down. I still want to test the application using local application.properties. Is there any way i could do this?
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
bootstrap.yml
server:
port: 8086
spring:
application:
name: PromoMS
security:
basic:
enabled: false
management:
security:
enabled: false
cloud:
config:
fail-fast: true
discovery:
enabled: true
service-id: ms-config-server
I am getting following exception
java.lang.IllegalStateException: No instances found of configserver (ms-config-server)
at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstances(ConfigServerInstanceProvider.java:48) ~[spring-cloud-config-client-2.2.2.RELEASE.jar:2.2.2.RELEASE]
To disable spring-cloud-config you and use your local properties, you need to add this property to your bootstrap.yml:
spring.cloud.config.enabled=false
And then enable it only when you need to run your application via application args, something like this:
java -jar your-application-name.jar --spring.cloud.config.enabled=true
While working on spring Microservices I am not able to route api through zuul proxy
This is my code
eurka:
application.yml
spring:
application:
name: api
cloud:
config:
enabled: true
server:
port: ${PORT:8761}
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: localhost
zuul:
application.yml
spring:
application:
name: proxy-server
server:
port: 8079
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
fetchRegistry: true
zuul:
ignored-services: '*'
prefix: /api
routes:
account:
path: /account/**
serviceId: account
stripPrefix: false
host:
socket-timeout-millis: 30000
ribbion:
eureka:
enabled: true
account
application.yml
ribbion:
eureka:
enabled: true
eureka:
instance:
preferIpAddress: true
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
dependency:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Now the url localhost:8080/user/ is working fine but localhost:8080/api/account/user/ is throwing a 404.
Not sure what wrong I am doing here, any insight will be helpful please let me know if you need other details
What you need to do is,
Generate a Spring boot project with Zuul as a dependency.
Annotate the main class with #EnableZuulProxy
Configure routes and endpoints in application.properties file
Build and start the service
I suggest to implement the above steps first and make them work. Then customize that project as per your need. Found below article explaining the above steps with more details.
How to build an API-Gateway with Netflix Zuul + Spring Boot
I think you forgotten to add the name the of account service in account application.yml
spring:
application:
name: account
I am able to use RABBITMQ and MYSQLSERVICES which is on pivotal.While binding services I am able to get the Credentials and using that credentials in my application.properties for spring data jpa project.
But this configuration that I am using is hard-coded in application.Properties To Make this configuration dynamically I came to know that we can use vcap services provided by pivotal.
So want to use run-time credentials for rabbimq and mysql.
My Code is below for reference.
File: application.propeties
rabbitmq.host=hostname
rabbitmq.virtual-host=vhost
rabbitmq.username=username
rabbitmq.password=password
rabbit.mainqueue=queue name
rabbit.errorqueue=erro queue name
spring.datasource.url=jdbc:mysql://hostname:postno
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
server.port=8000
The below is the repository file
package com.redistomysql.consumer.repo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface tblemployee_personal_infoRepository extends JpaRepository<tblemployee_personal_info, Long> {
}
Any help would be appreciated.
The link for reference **http://www.java-allandsundry.com/2016/05/approaches-to-binding-spring-boot.html**
Set this configuration in application-cloud.yml for Mysql
---
spring:
datasource:
url: ${vcap.services.mydb.credentials.jdbcUrl}
username: ${vcap.services.mydb.credentials.username}
password: ${vcap.services.mydb.credentials.password}
The config for rabbitMq:
System.getEnv("VCAP_SERVICES")
The dependencies in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app on Cloud Foundry, add the following -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-heroku-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
**The manifest.yml**
---
applications:
- name: redistomysql-consumer
path: target/redistomysql-consumer-0.0.1-SNAPSHOT.jar
memory: 1024M
env:
JAVA_OPTS: -Djava.security.egd=file:/dev/./urandom
SPRING_PROFILES_ACTIVE: cloud
services:
- es-mysql-db
- es-consumer-rabbitmq-service
buildpack: https://github.com/cloudfoundry/java-buildpack.git
env:
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'