I have been doing a line by line study of the code in this spring cloud app on github after downloading and installing it on my devbox. When you type http://localhost:8080 in your web browser, the content from the ui app loads, and is able to interact with the content from the authserver and resource apps.
Port 9999 is defined for the authserver app, both in the ui app's zuul route definitions, and also in the authserver app's application.properties.
Similarly, port 9000 is defined for the resource app, both in the ui app's route definitions, and also in the resource app's application.properties.
But I cannot find any reference to port 8080, even after reviewing every line of code in the three apps and also doing a Ctrl-H to do full text search of the entire eclipse workspace for the word 8080.
So how does the ui app know to serve its client content on port 8080?
The UI module has the following Spring Boot dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
That dependency has its own dependencies as seen here:
Spring Boot Starter Web POM.xml
This includes the Spring Boot's Tomcat Starter:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
Which brings in the actual Tomcat embedded jars
Spring Boot Starter Tomcat POM.xml
Because the UI application is a Spring Boot app (eg it uses the Spring Boot Parent POM and has annotated its main class with #SpringBootApplication) it will autoconfigure many things for us based on the Classpath.
Notice the #ConditionalOnClass annotation in this class:
EmbeddedServletContainerAutoConfiguration
That eventually leads to this class:
TomcatEmbeddedServletContainer
Which triggers the startup of the embedded Tomcat server.
The Default Port 8080 setting is actually coming from the embedded Tomcat dependency as seen here:
org.apache.catalina.startup.Tomcat
protected int port = 8080;
You can use a .properties or .yml file to store all the configuration of your application. There you can define the server port property to listen in whatever port you want.
If you use a .properties file it would be something like this :
server.port=8082
Or in a .yml file it would be something like this:
server:
port: 8082
For more about properties and configuratio in spring, check this
there is a reference of all spring boot default properties which should be checked as soon as you hit some unknown defaults :)
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
Related
I want to enable actuator for health check in PCF for the non web or batch or commandLineRunner spring boot application.
Could some one please share some details to resolve this issue.
Please let me know if any other details required
I tried the below options
Adding actuator dependency
Adding http and jmx related properties
Since localhost:8081/actuator is not accessible could not view endpoints
How to enable url for non web app
add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
application.properties
spring.jmx.enabled = true
management.endpoints.jmx.exposure.include=*
management.endpoints.jmx.domain=com.example.demomail
management.endpoints.jmx.unique-names=true
run jconsole find your application name then connect.
find Tab MBeans, find com.example.demomail in left tree.
As far as I understand you need to enable the Actuator endpoints.
You must add the Spring Boot Actuator dependency (as you have already done).
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Then in your application.properties file enable HTTP and JMX support (as you have already done).
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.endpoint.jmx.exposure.include=*
Now you will have to push your app to PCF and create a binding to a route to create access for the Actuator endpoint/s.
The URL to access the actuator endpoint will be something like this http://<route-url>/actuator/health
In the command line, I would use something like this to return a list of routes and the URL route of the application.
cf curl /v2/apps/<app-guid>/routes
I'm trying to set up spring-boot-admin via war deployment. for war i'm not able to see the client application in spring boot admin dashboard.
I've tried with spring boot version 2.1.6 and tomcat version 8.5.47 but i'm not able to see the client application in dashboard.
My client application POM
<version>1.0.0</version>
<packaging>war</packaging>
<name>spring-boot-admin-client</name>
<description>Demo project for Spring Boot Admin - Client</description>
Dependencies I have used:
spring-boot-starter-actuator
spring-boot-admin-starter-client
spring-boot-starter-security
spring-boot-starter-test
spring-boot-starter-web
Not getting any error message but client application i'm not able to see it in spring-boot-admin dashboard.
Have u configured spring.boot.admin.client.instance.service-url property in client application?
Generally when Spring Boot Client is installed on external tomcat, SBA predicts the actuator endpoints path as http://server:port/actuator while the actual path is http://server:port/context-root/actuator.
This is where spring.boot.admin.client.instance.service-url property comes to the rescue. spring.boot.admin.client.instance.service-url should be set as http://server:port/context-root
I want to refresh the properties files in spring boot.
version - 2.1.4.RELEASE
In case of spring config server have to connect all my app to config server which i dont want as our application is in prod and we dont want a bigger change.
Is it possible in the same application i can refresh the prop file using config server if not using config server then using some spring code
can i do it.
NOT application.properties , Have a application-optional.properties outside of project want to refresh only this.
The RefreshEndpoint is provided by Spring Cloud. Adding the spring cloud starter config will get you the required beans and API to refresh.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Additionally you will need to expose the API via management.endpoints.web.exposure.include="health,info,refresh" or you can use "*" to expose every enabled actuator endpoint to the web.
I have a spring cloud project. There are config server (config-srv), eureka server (eureka-srv) and some other service with business logic, let's call it main service (main-srv).
I'm packaging them into jars and run one by one. My apps get their properties from a file in the same directory with jars.
So, I'm setting properties to config-srv through "application-native.properties".
But if i want to change config-srv url (for example, i want http://localhost:9999), how can i share this url for all micro-services before they will boot ? I'm trying to share this url in "application-default.properties" but it makes no effect.
You can put the Spring Cloud Config server details in bootstrap.properties file in each microservices.
spring.application.name=microserviceName
spring.profiles.active=dev
spring.cloud.config.uri=http://localhost:9999
spring.cloud.config.username=your_username
spring.cloud.config.password=your_password
Go through the link to have more detail about spring cloud config
https://howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/
For security purposes, I'd like to have javamelody running on my app management port, not the main traffic port. This is a 1.5.13 spring boot app running jetty with some actuator endpoints enabled. I have set the actuator property management.port to something other than the server.port.
I can run javamdelody in a standalone jetty server on a third port using an approach like this github project. But three ports is a little wieldy in a micro-service context.
This stackoverflow post has answers for Tomcat, but not for Jetty. Any suggestions to run javamelody on the management port with Jetty?