Look at the Springboot official website example, there is only a simple example of hello, there is no integration mybaits related. Then found on the internet a lot of looking for an integrated demo program, are too redundant, not suitable for learning. Do not say nonsense, the following is a self-organizing demo program 1. Build a MAVEN Project
2. Import related dependencies.
3. Create a table in the database to test
4. Add a application.properties configuration file, configure the associated
driver-class-name: com.mysql.jdbc.Driver hikari:
pool-name: HikariCP
auto-commit: false
...
ro-datasource:
jdbc-url: jdbc:mysql://localhost/test username: ro password: ro_password
driver-class-name: com.mysql.jdbc.Driver hikari:
pool-name: HikariCP
auto-commit: false
...
In the development environment, it is not necessary to configure the master-slave database. Only need to set two users to the database, onerwwith read and write permissio
. autoconfigure. springBootApplication;/*** @ author chiwm@kuyumall.com * @ ClassName: Application * @ Description: * @ date 2018/1/3 am */@ SpringBootApplication (scanBasePackages = "info. chiwm. log4j2 ") public class Application {public static void main (String [] args) {SpringApplication. run (Application. class, args );}}
You can directlyApplication.javaWritecontrollerThe business logic is started.1.2.
the service registration and Monitoring module development, as well as the development of service calls, others can directly refer to the above series of articles.Development of registration and monitoring CenterThis is very simple, just one of the following classes:Omit Import@springbootapplication@enableeurekaserver@enablehystrixdashboardpublic class ApplicationRegistry { public static void Main (string[] args) {new Springapplicationbuilder (Applic
Components in RibbonClientConfiguration and any components in FooConfiguration (the latter usually overwrites the former ).
WARNINGThe FooConfiguration has to be @ Configuration but take care that it is not in a @ ComponentScan for the main application context, otherwise it will be shared by all the @ RibbonClients. if you use @ ComponentScan (or @ SpringBootApplication) you need to take steps to avoid it being stored ded (for instance put it in a se
); }}
※ @SpringBootApplication annotations provide automatic configuration for the project based on the content in Classpath. In this application, it is equivalent to: @Configuration,@EnableAutoConfiguration, @ComponentScan the union of the three.
3.2 Create the form file Fuck.java under the Com.example package as follows: PackageCom.example;/** * @ClassName: Fuck * @Description: TODO (here is a word describing the role of this class)
@ComponentScan,@EntityScanand the@SpringBootApplication, which we usually use to annotate the startup class. The startup class of Spring boot, which is also the main class, is usually placed under the root folder. For example:Package Testredis.main;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.beans.factory.annotation.qualifier;import Org.springframework.boot.springapplication;import Org.springframework.boot.
Spring Boot + Mybatis multi-data source and dynamic data source configuration method, mybatis Dynamic Data
The articles on the Internet basically only have multiple data sources or only dynamic data sources. The latest projects need to use two methods at the same time. Record the configuration methods for your reference.
Application scenarios
The project needs to connect two different databases A and B at the same time, and they are both master-slave architecture, one write database and multiple
service has two units running:
192.168.21.101:compute-service:2222
192.168.21.101:compute-service:2223
Consumer with ribbon for client load BalancingBuild a basic spring boot project and include the following in Pom.xml: In the application main class, the @EnableDiscoveryClient Discovery service capability is added through annotations. Creates a Resttemplate instance and @LoadBalanced opens the load balancing capability with annotations.@
when you use @componentscan annotations, when you do not declare any parameters, the default is to scan the same package, and the class under the sub-package, so that you can scan to classes such as Controller,service.It is important to note that @Import can import additional configuration classes, @ImportResource can import other profiles. But you can search for other beans, including configuration classes, through @componentscan.1.4 Disabling a specific automatic configurationYou can do this
solrautoconfiguration This class @SpringBootApplication (Exclude=solrautoconfiguration.class) @ImportResource (locations= "Classpath:conf/dubbo.xml ") public class App extends Springbootservletinitializer {@Overrideprotected Springapplicationbuilder Configure ( Springapplicationbuilder builder) {return builder.sources (app.class);} public static void Main (string[] args) {Springapplication.run (app.class, args);}}This problem actually tells us th
; dependencies> dependencymanagement> dependencies> dependency> groupid>org.springframework.cloudgroupid> artifactid>spring-cloud-dependenciesartifactid> version>brixton.releaseversion> type>pomtype> scope>importscope> dependency> dependencies> dependencymanagement>
Create a spring boot program main class and add @EnableConfigServer annotations to open config Server
123456789
@EnableConfigServer @Spring
configuration file packagecom.wisely.ch7_4;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public classch74application { public Static voidmain (string[] Args) {springapplication.run (ch74application.class, args); } @Component public Static classCustomservletcontainerImplementsembeddedservletcontainercustomizer{//Note In spring configuration that the current c
application Class in a root package above other classes.) */@SpringBootApplication //same as @[email Protected][email protected]public class Application { /** * Spring boot entry, within the entire subproject, * There can be only one main method, otherwise spring boot does not start * /public static void main (string[] args) { Springapplication.run (Application.class, args);} }View CodeAttention:
The main c
This article turns from http://www.cnblogs.com/zheting/p/6707035.html thanks to the author Spring Boot Dry series: (iii) Starting principle analysis2017-03-13 toot md du ye Java Super Theological hall ObjectiveIn the first few chapters we have seen the springboot for us to do automatic configuration, indeed convenient and fast, but for beginners, if not understand springboot internal starting principle, will inevitably suffer. So this time the blogger will be with you step by step to uncover the
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.