Recently in the use of Spring boot development project, which has a project to use a multi-data source configuration, online information or not too much, go a lot to find a suitable, write their own share, make a note, may be useful, the first blog, not to spray!!Let's start with my business scenario, which uses two types of databases, one MySQL and the other SQL
Redis is used as a cache in the most recent project, and the database is MongoDB. Project uses spring and everything works without introducing Redis, but add in Pom.xml:
When a dependency on Redis is introduced, no other action has been done at this time. Start the project will error, the error reason is unable to rely on injection MongoDB Repository.
Method One:
How to load some initialization data that is needed for startup.To solve this problem, spring Boot provides a way for us to implement the interface Commandlinerunner. No additional configuration is required, so just create a class to implement the interface Commandlinerunner.
After the Spring
Application.properties file and to set properties for the Bean* @return Data source*/ @Bean("Master") @Primary @ConfigurationProperties(prefix ="Application.server.db.master") PublicDataSourceMaster() { returnDatasourcebuilder.create (). build ();}@Bean("Slave") @ConfigurationProperties(prefix ="Application.server.db.slave") PublicDataSourceslave() { returnDatasourcebuilder.create (). build ();}@Bean("Dynamicdatasour
Spring Boot RestTemplate: three methods for submitting form data: springresttemplate
In the REST interface design, using RestTemplate for interface testing is a common method, but in the process of use, due to the large number of method parameters, many people confuse the differences between the form submission and Payload submission methods, and the interface de
If we want to use a third-party JSON parsing framework in spring boot:1) We need to introduce third-party package dependencies in the Pom.xml file;2) Implementation method:Method 1 requires inheriting the Webmvcconfigureradapter class in the startup class and overriding the Configuremessageconverters method of the class.Method 2. We use @bean to inject third-party analytic frameworks directly.1, the introdu
Use spring boot to retrofit an old project because there are multiple data sources and the following error has been reported at startup
caused By:org.springframework.beans.factory.NoUniqueBeanDefinitionException:No qualifying bean of type [ Javax.sql.DataSource] is defined:expected single matching beans but found 5:
Turned out to be
@EnableAutoConfigurationThi
First we create a MAVEN project, such as:Step Two: Configure Pom.xmlStep three: Create the package structure and class as shownFourth step: Write the above three classesUser:Provides a get, set method.Fastjsoncontroller:APP:When the above steps are complete, execute the main method of the app class, waiting for the project to start. And then access it in the browser.Http://localhost:8080/getJson, return results such as:Find Chinese garbled, then modify the controller class, such as:And then visi
First we create a MAVEN project, such as:Step Two: Configure Pom.xmlStep three: Create the package structure and class as shownFourth step: Write the above three classesUser:Provides a get, set method.Fastjsoncontroller:APP:When the above steps are complete, execute the main method of the app class, waiting for the project to start. And then access it in the browser.Http://localhost:8080/getJson, return results such as:Find Chinese garbled, then modify the controller class, such as:And then visi
Spring-boot official case analysis of the DATA-JPAPackage SAMPLE.DATA.JPA;Import Org.junit.Before;Import Org.junit.Test;Import Org.junit.runner.RunWith;Import org.springframework.beans.factory.annotation.Autowired;Import org.springframework.boot.test.SpringApplicationConfiguration;Import Org.springframework.test.context.ActiveProfiles;Import Org.springframework.t
updates or deletes the data, and the other transaction two times queries the data inconsistently.
Phantom reads: One transaction adds a new operation to the data, and the other transaction two times queries the data is inconsistent.
Dirty reads: Primarily for column content changes.
Phantom reads: Mainly for the chang
In the case of a single data source, the Spring boot configuration is very simple, just application.properties configure the connection parameters in the file. But often as the business grows, we usually split the database or introduce other databases, so we need to configure multiple data sources, based on the previou
To use @[email Protected]@[email protected] in spring data mongodb four annotationsMust implement SpringsecurityauditorawareOfficial codeclass Springsecurityauditoraware implements auditoraware { public User Getcurrentauditor () { = securitycontextholder.getcontext (). Getauthentication (); if Null | | ! authentication.isauthenticated ()) { returnnu
=" Person") Public classPerson {@Id//JPA is not supported for UUID, but it can be implemented using hibernate. @GeneratedValue (generator ="UUID") @GenericGenerator (name="UUID", strategy ="Org.hibernate.id.UUIDHexGenerator") PrivateString ID; PrivateString name; PublicPerson (string ID, string name) {super (); This. ID =ID; This. Name =name; }... Setter/getter method}Iv. RepositoryPackage Com.ltchu.design.repository;import Org.springframework.data.repository.crudrepository;import Com.
problem
When you select a data source for a project framework that is automatically generated by springboot, such as by selecting MySQL, the startup will report an exception after the project is built:
Description:
cannot determine embedded database driver class for database type NONE
Action:
If your want an EMB edded database Please put a supported one on the classpath. If you are have database settings to is loaded from a particular profiles you
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.