How to change crashHub port in Springboot - spring

I am using Springboot in my project, i start an embedded Springboot application inside my App. My app is already having a crashHub which is conflicting with springBoot's crashHub, so how i can change the springBoot's crashHub port, I don't want to do it through a XML File.

There's an extensive list of configuration properties in Spring Boot's documentation, including those for configuring the ports used by the remote shell: shell.ssh.port and shell.telnet.port.
You should configure one or both of these properties in your application.properties file in src/main/resources.

Additionally, you can do it by specifying parameter to java:
-Dshell.ssh.port=<your-port>
Or command line argument for you application:
--shell.ssh.port=<your-port>

Related

Using jasypt-spring-boot when deploying to Apache Tomcat

I'm trying to use the jasypt-spring-boot and deploy it to a Tomcat server as war.
How to pass the encryptor password, in this case, to ensure the encrypted values could be read?
All the provided example are about running a jar file or a Spring Boot app as follows:
java -Djasypt.encryptor.password={my-password-to-decrypt} -jar target/jasypt-spring-boot-demo-0.0.1-SNAPSHOT.jar
May be add some settings to catalina.properties file in the Tomcat conf folder as we do for example when defining active profile?
I figured out how to achieve that:
create a setenv.sh file in CATALINE_HOME/bin folder
add the following entry to set the environment variable on the Tomcat startup:
export JASYPT_ENCRYPTOR_PASSWORD=your-password
save and restart Tomcat.

Spring Boot Configuration File Location From Tomcat

I'm trying to setup backend application so it gets different configuration files depending on env.
On dev env I would like to load default application.yml from classpath. This should be the case when I'm running the app via: mvn spring-boot:run or java -jar ./target/myapp.war
But when this app is running on Tomcat it should load application.yml from server specific file e.g. /etc/apps/myapp/application.yml (not default one from classpath) because server has different mongodb credentials etc...
I don't want to use profiles because this mean I need to put server credentials in project on github in application.yml. I just want that this is known by server administrator and developer don't know anything about it.
Is there any way how can I tell this application inside tomcat to load different configuration file.
In this Tomcat I have other applications that are using spring boot so I need some solution that is independent. Setting globally spring.config.location is not the case because all apps will load this one file.
You can use #PropertyResource annotation with context xml.
NOTE: ignoreResourceNotFound will help not throw exception when file not found, say for Dev env.
#Configuration
#PropertySources({
#PropertySource("classpath:application.properties"),
#PropertySource(value = "file:${config.file}", ignoreResourceNotFound=true)
})
public class AppConfig {
//...
}
/META-INF/context.xml
<Context>
<Parameter name="config.file" value="/yourpath/application.properties"/>
</Context>
If you don't want to save path in context.xml inside your project, there are other ways to define application level context depending on your tomcat version. Please refer here for details for tomcat 9.
If you want to read properties from external location then write bootstrap.yml in your application and delete application.yml.
bootstrap.yml:
spring:
config:
location: file:/home/external/properties/location/
name: application
profiles:
active: dev
file location: /home/external/properties/location/
suppose you need dev and prod environment.Then keep this 3 properties file in this location.
application.yml
application-dev.yml
application-prod.yml
Spring boot read application.yml properties first. If set active profile dev in bootstrap.yml then application.yml value overwirte by application-dev.yml.
Or you can use config server
Look at this

Specifying application config file by name when Spring Boot starts up

Currently I can build my Gradle-based Spring Boot app like so:
./gradlew build && java -Dspring.config=. -jar build/libs/myapp.jar
And this works fine provided I have an application.yml in the root of my project directory.
However, I would now like to have both an application-local.yml as well as an application-dev.yml, and to specify which one to use when I build + run myapp.jar.
How can I specify either file at startup?
You can use Spring boot's capability of using Profile Specific property file.
You can specify the application yml inline with your profile name
application-[profile].yml. In your case, it would be
application-dev.yml
application-local.yml
Specify the profile you would want to use as a command line argument
-Dspring.profiles.active=dev

Spring Boot external properties file (with profiles)?

What I am trying to accomplish, is to specify a directory on my application.yml file located directly on the classpath (under /resources). I would like to be able to have something like:
spring:
datasource:
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
profiles:
active: dev
config:
location: C:\\app\\configs\\
Then under the c:\settings\configs\ location, I would like to have multiple config files based on the profile being loaded, such as:
c:\app\configs:
application-dev.yml
application-staging.yml
application-production.yml
Using this approach, the IDE would always default to application-dev.yml. When I build the app via gradle, and run it while passing in the command line arguments, I can specify the profile, thus loading the appropriate file. Ideally, being able to do just this:
java -jar -Dspring.profiles.active=staging appliation.jar
All the examples or answers I've seen have shown how to pass this all these config options from the command line only, not using
spring.config.location
and
spring.profiles.active
from within a default config file (eg: application.yml). Preference is to set this up as described above for minimal deployment.
Thank you for any suggestions / help!
You could give it a try and provide your base configuration as "bootstrap.yml" instead of "application.yml". Afterwards, spring boot should choose the right config depending on the chosen profile from your configuration path.
To me, this seems to be the closest solution to your use case, if you do not want to make use of command line arguments.

Build Spring project for run on another system

I Successfully create a spring boot project on my own local system. I want to build a jar file so I can install it on remote server. so I had to configure server address and mySql address of remote server but I can not Build and it have many errors, and they all right cause my system can not see the remote server address and database.
this is my .properties file:
spring.datasource.url=jdbc:mysql://localhost:8081/aths
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create
server.address=192.168.24.250
server.port=8080
how can handle it for running on another configurations? ( another IP, datasource, and ...)
Am I doing it right or not? thanks
You can use spring profiles here :
Create different property files for different profiles using application-{profile}.properties format, e.g. application-dev.properties for dev, and application-prod.properties for production put your profile specific configurations in them. Then when you're running the spring boot application, activate your intended profile using the SPRING_PROFILES_ACTIVE environment variable or spring.profiles.active system property.
and at the end, you will run your jar file with command
java -jar -Dspring.profiles.active=prod application.jar
You can have different application.properties within your resources folder and use spring profiles for example application-{profile}.properties and run the application with the specified profile. However this still limits the configuration items to what has been hard coded within the properties files. When running the application, if it was to be distributed to other people, where non of the profiles are supported you can provide a properties file at start up.
So in the same directory for example as the .jar file create a file named application.properties with empty place holders for all the variables required for the application so the admin can enter the details correct for them. Then they will be required to start the application with the following command
java -jar 'applicaitonname.jar -Dspring.config.name="file:/path/to/application.properties"
Or springboot will load properties from application.properties files in the following locations:
A /config subdirectory of the current directory.
The current directory
Failing that the default application.properties from the resources folder will be loaded.

Resources