Defining Database dynamically in spring boot maven based war application - spring

My Spring boot application won't know the database to be connected in prior, once before application deployment, the user will select the database to be connected, and places the jar in the server webinf(or probably some other repository path), and changes the externalized properties file, so that application connects to the database, I was trying giving the database dependency scope as provided, but getting class not found. What is the preferred approach for solving the issue?

You can run your Spring Boot bootJar like this:
java -cp your-jdbc-driver.jar -jar your-boot-jar.jar --spring.datasource.url=your:jdbc:url

Related

how to add reference of one spring boot application to another spring boot app

I want to make a spring boot product base application.
In that I want to make a different spring application depends on each other by adding reference of one application to another application.
And make seperate jars of each and put it into tomcat
I would like to suggest you to start with simple hello-world application and later you can scale your application up.
Simple way is go to 'start.spring.io', add dependencies like spring boot starter web.
You can download the project after adding dependencies. Now, just import the project in your eclipse as 'import existing maven project'.
Spring boot has inbuilt tomcat, simply right click on the import project and select
run as --> java application
Your application will start on port 8080.
Now, you can create one more similar application and can run the application on port 8081 by adding a property server.port=8081 in your 2nd application.
You can call the api of 1st application from 2nd application.
If you are planning to create microservices, then please read about spring cloud.

Two or more spring boot application sharing same port

I have a use case where I need to run atleast two or more spring boot applications on the same port.
I am able to run spring boot applications via mvn spring-boot:run -Pdev... port and other information. I have provided following configuration in spring boot projects
server.port= 8597
server.contextPath=<as per the project>
spring.config.name=<project name>
With this configuration, I successfully run two spring boot application on same port i.e. 8587.
Now, here the problem comes, when I package the project as jar for dist purposes and run the application as java -jar <profile>..... second boot project run fails with Address already in use.
I am not able to understand where I am going wrong. I even tried passing context, port and config name in vm arguments but no success.
Any help?

Spring boot datasource specific properties for embedded jetty server

I have spring boot application and it's basically a gradle project, so, I have below dependency added in my gradle file:
org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE
Application gets deployed in embedded jetty server. I have following set of properties in application.properties for db connection polling:
spring.datasource.driver-class-name
spring.datasource.max-active
spring.datasource.max-idle
spring.datasource.min-idle
spring.datasource.validation-query
spring.datasource.name
I was referring to below two links:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Configuration-Changelog
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.5-Configuration-Changelog
I came to know that some of the datasource properties which used in application.properties file in my application are removed starting sprint boot version 1.4 but issue they haven't mentioned what are the new properties to use. Like for tomcat server they have provided all set of properties but not for jetty server. I am facing some db related errors like 'too many connections' after my application run for sometime, my assumption is that datasource props I am currently using are not correct and should be replaced with correct values, but unfortunately I am unable to find correct property names.
Jetty doesn't have its own Pooling DataSource implementation. You can include HikariCP in your project and customise using the spring.datasource.hikari.* properties. With each property matching the bean properties that can be set on Hikari's datasource implementation.

The gradle can build runnable jar made by spring boot to war file?

I made my application using spring boot. It use embedded servlet container using tomcat library and run as application. Because I use spring boot annotation in main class for running. I used it in the local, But I have to make this application buidld war file to send the remote server where tomcat instance is listening.
First, I want to ask this gradle plugin I found can to it to generate the war file even if it have a main class and doesn't follow original webapp style
Second, Is there any other gradle plugin to send the war to the remote server and make tomcat redeploy the war file I sent?
Thanks in advance.
It seems to me that you have the answer to your first question in the documentation. Spring Boot war is nothing different from traditional war so I am not sure I understand what you mean. Perhaps Converting a Spring Boot JAR Application to a WAR would help?
For your second question gradle remote deploy war on Google gave me this

How to configure wily with spring boot application

I have created an application as spring boot application,Now i want to integrate this application with wily,where i ll passed wily parameter in application to configure application.
The fact that it's a Spring Boot application shouldn't make any difference. If you're using an executable jar file, you'll need to configure the agent when you launch the jar, for example:
java -jar my-app.jar -javaagent:<Agent_Home>/Agent.jar -Dcom.wily.introscope.agentProfile=<Path_To_Agent_Profile>
If you're deploying your Spring Boot application as a war file to a servlet container or application server, you'll need to be make the equivalent configuration changes. The documentation describes how to configure Tomcat.

Resources