Building a Maven Project
Use the official Spring INITIALIZR tool to generate the base project and access the http://start.spring.io/, as shown in this page, which provides the ability to build a Spring Boot project with maven.
Choose the Build tool Maven project,spring
method is more formal thinking, but in my current experience of the project is not used much, today summarizes how to use mock Object Test controller layer code.In previous articles, we used the bookpub application as an example, and today is no exception, ready to test whether the RESTful interface it provides returns the correct response data. This test is different from unit testing , where the full application context needs to be initialized, all
(RetentionPolicy.RUNTIME)@Documented@Import({ EnableAutoConfigurationImportSelector.class, AutoConfigurationPackages.Registrar.class })public @interface EnableAutoConfiguration { /** * Exclude specific auto-configuration classes such that they will never be applied. */ ClassThe Enableautoconfigurationimportselector class uses the Loadfactorynamesof () method of the Springfactoriesloader class of the spring core package. The Spri
complex. In order of precedence from highest to lowest, the specific list is as follows.
command-line arguments.
The Java system parameters obtained through System.getproperties ().
Operating system environment variables.
The JNDI attribute obtained from java:comp/env.
The "random.*" property generated by Randomvaluepropertysource.
apply a property file other than the Jar file . (via spring.config.location parameter)
Apply the properties file inside the Jar file
Spring Boot and Kotlin use the Redis database configuration method, kotlinredis
In addition to providing excellent automation support for common relational databases, Spring Boot also provides automated configuration support for many NoSQL databases, including Redis, MongoDB, Elasticsearch, solr and Cassandra.
Use Redi
verify it by visiting it.Also, you can randomly place index.html on the top of a path, and when we access the app root http://lcoalhost:8080, it maps directly to the Index.html page.The corresponding configuration file is configured as follows:We can modify the default mappings by modifying the Spring.mvc.static-path-pattern, for example, I change to/dudu/**, which accesses http://lcoalhost:8080/dudu/index.html when running. Corresponds to the index.
, throw MyException exception[Java] View plain copy@Controllerpublic class Hellocontroller {@RequestMapping("/json") public String json() throws MyException { throw new MyException("发生错误2"); } }Create a corresponding processing for a myexception exception[Java] View plain copy@ControllerAdvicepublic class Globalexceptionhandler {@ExceptionHandler(value = MyException.class) @ResponseBody public ErrorInfo}Launch app, Access: Http://localhost:8080/json, you can get the following return co
; @SpringBootApplication @RestController public class application { @RequestMapping ( "/") public String greeting () {return "Hello world!";} public static void main (string[] args) {Springapplication.run ( Application.class, args); }} Run app: mvn spring-boot:run or run Main () method in the IDE, Access http://localhost:8080 in the browser, Hello world! appears on the page. With just more than 10 lines of Java code and a Hello World app ru
priority order provided by Spring Boot is more complex. In order of precedence from highest to lowest, the specific list is as follows.
command-line arguments.
The Java system parameters obtained through System.getproperties ().
Operating system environment variables.
The JNDI attribute obtained from java:comp/env.
The "random.*" property generated by Randomvaluepropertysource.
="]60mb%{(o2a () v{13i7jf_4.png "alt=" Wkiom1k4_0txrdomaadczc7n2tw571.png-wh_50 "/>The default name is example,Let's change it a little bit and change it to demo001650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/98/3C/wKioL1k4_83CU5mcAAEvg3pU1VM053.png-wh_500x0-wm_ 3-wmp_4-s_1563062793.png "title=" Rrra$m ' vmos1@y9kb (PW (2o.png "alt=" wkiol1k4_83cu5mcaaevg3pu1vm053.png-wh_50 "/ >Interface I have changed, may not be the same as the defaul
Spring Boot Log Record slf4jJanuary 12, 2016 09:25:28Hits: 54086Printing content in development, using SYSTEM.OUT.PRINTLN () and log4j should be a well-known approach.In fact, in development we do not recommend the use of System.out because a large number of use of system.out will increase the consumption of resources.LOG4J is more flexible in performance than System.out, we can configure the output level,
exception information logging and query.Connection pooling monitoring: monitor the status of the current system database connection pool to analyze SQL to identify system performance bottlenecks.Source source technical support for complete projects 17917433806. Source code Structure7. Registration Center8. Some functionsYou are welcome to study the relevant technology to understand the framework of technology or source of friends directly to seekSour
exception information logging and query.Connection pooling monitoring: monitor the status of the current system database connection pool to analyze SQL to identify system performance bottlenecks.Source source technical support for complete projects 17917433806. Source code Structure7. Registration Center8. Some functionsYou are welcome to study the relevant technology to understand the framework of technology or source of friends directly to seekSour
engine (no separate Web server required), the service should start on its own at the command line, and be accessed immediately through the exposed HTTP port.Concurrency: To initiate more micro-service instances to scale horizontally when demand increases.Can be arbitrarily disposed of: you can start and stop as needed.The development environment is equivalent to the production environment: minimizing the gap between all the environments in which the service runs.LOG: Use the tool to log and vie
AOP is the abbreviation of Aspect oriented programming, which means: face-cutting programming, through the pre-compilation method and run-time dynamic agent implementation of the unified maintenance of the program functions of a technology. AOP is an important part of the spring framework by defining an entry point for an existing program and then cutting into different executions before and after it, such as: Opening a database connection/closing a d
Quick StartThe main objective of this chapter is to build the Spring Boot Foundation project and implement a simple HTTP request processing, which gives a preliminary understanding of spring boot and experiences its simple structure and rapid development.System Requirements:
Java 7 and above
Brief introductionDid you retreat from the complex configuration when you first contacted and learned the spring framework for the 1th time? When you use the Spring framework for Nth times, do you feel bored with a bunch of sticky configurations? Try spring boot to make it easier and faster to build your
The configuration of the data source can be followed by the example of Spring boot Learning (vii) Web applications using the Datasourceconfig implementation of JdbcTemplate multiple data source configuration. Add the JPA configuration for the first data source, note the two notes where you specify the Entity entity and Repository defined location for the data sou
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.