I am having a Java standalone application, which is using the Spring core container and spring jdbc. I have different database environments like dev,int,uat,prod. These database configuration details and datasources for each environments are configured in spring configuration file spring-beans.xml along with the DAO beans.
Now i have to update the application, like if i passed a particular the database environment(like dev,int,uat,prod) as arguments at the time of running the application, the application will invoke the database as mentioned in the arguments. is there any way out?
i think you should used spring with hibernate it much easier or you can use JDNI for that
db1Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db1
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root
db2Jndi=
jdbc.url=jdbc:mysql://localhost:3306/db2
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.username=root
jdbc.password=root
Related
I am trying to write Spring Boot application to connect to a Teiid database, I want to use JPA layer on it. I have configured the JDBC Data Source, but since this not well-known database in Spring JPA libraries do not autodetect this source. I have manually setup "spring.jpa.*" properties too. I do have a Hibernate dialect for this database, and it is on the classpath.
So, how does one need to configure JPA layer for a not well-known database in Spring Boot? Thank you for your time.
Ramesh..
This is fairly well defined in the Spring Boot documentation.
You can set this explicitly in the application.properties file
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
One of the Spring framework advantage is dependency injection. Many had used SpringBoot for providing REST Web Services.
Read up and notice there are Scheduler and CommandLineRunner for SpringBoot, could we using SpringBoot for backend type of application to replace the usual standalone java program while making use of SpringBoot advantage (Dependency Injection)
- Cron Job (Execute and stop running)
- Long Running Process
One of the main thing I am looking into is to use annotation such as Spring Configuration, Spring Data JPA and other technology in backend application.
Of course!
I used spring boot to back CLI projects, DB access projects and more.
Spring boot is very modular. It works by providing auto-configuration based on your maven/gradle imports. If you don't import starter-web/starter-jersey or any other starter that is for the web/rest api, the auto-configuration for this resources won't be triggered and you can basically enjoy all the power of spring boot to support your needs
Definitely,
Spring boot is not a separate framework.It reduces the configuration difficulties when you using spring framework. Spring boot provides a Rapid Application Development using without complex configuration including your dispatcher servlet, XML file for database connectivity and configuration files. You can use spring boot for back-end development. Simply says you can do everything what you does in spring MVC without any complex configuration. If you are using spring boot , You can configure your database details in application.properties file. I am adding one of two links for proper reading,
https://projects.spring.io/spring-boot/ ,
https://dzone.com/articles/why-springboot
I would like to use Flyway as preferred way of database migration handling in my Spring Boot project (using current V1.2.1.RELEASE).
This is working fine so far however the integration with Spring Security using a JDBC DataSource seems to override the Flyway mechanism.
Following simple scenario:
Spring Boot 1.2.1
PostgreSQL 9.4.1
Flyway migration scripts for users, groups and authorities according to Spring Security documentation
Problem:
The Flyway migration scripts are not executed at startup as expected.
Maybe cause: It seems that Flyway is only executed at startup if the using Spring Boot project is also using JPA at least. Since Spring Security is based on plain JDBC, I've tried to temporary use the JDBC based database initialization scheme as described in Spring Boot docs (Chapter 68.3) which works, but (as documented) this way is like the 'poor man approach' and I'd really like to use Flyway also for these tables containing the User/Group/Authorities information.
Ok, after some further investigation I've found the problem:
Indeed, in a standard Spring Boot project the security context is initialized before any Flyway based migration takes place.
Normally this is not a big issue, but I've also used the AuthenticationManagerBuilder for creating a default admin user. This seems to be the wrong approach for creating such an initial user account.
I am trying to understand Spring Petclinic Application.
By default it seems that HSQL database and JPA is used, but I am unableto to find where the Hibernate Dialect for HSQL is mentioned in the application.
I understand that it is a mandatory property for Hibernate.
Kindly suggest
What about where org.hibernate.dialect.HSQLDialect and where the driver is org.hsqldb.jdbcDriver. Normally, if this is a Spring application, this will be present in an applicationContext.xml or tx-datasource.xml configuration file. Whatever is the case, these properties must be in one of the XML Spring configuration files. Of course, they may be in a Java class (an alternative), but in most applications, they are present in Spring XML files where the dataSource bean is defined. Usually, in web applications, that would be in directory under /WEB-INF or /webapp/WEB-INF.
I want to use Spring framework to create application that uses Oracle 11g to store data.
Can you tell me how to configure the Spring framework to use the connection pooling with JBoss 7 and Oracle 11g.
Is it possible to put this code onto OSGI bundle?
You have to configure your datascource in JBoss first. After configuring your datasource it should hava a JNDI name like "jdbc/yourDataSource".
You can now reference this datasource from your spring context.
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/yourDataSource"/>
Have a look at the documentation
If you use relative JNDI names then you have to put additional settings into the web.xml. For global nameing set resource-ref="false". For Spring it should not matter what database you use as its managed by the application server.
I cannot tell you if you can use it in a OSGI bundle.