Discover spring boot starter web reactive, include the articles, news, trends, analysis and practical advice about spring boot starter web reactive on alibabacloud.com
Spring boot starts the web, embedded tomcat, springtomcat
1. Configure the pom. xml file (as appropriate)
2. entity class User
package com.nnk.maven.test.entity;/** * */public class User {private Long id;private String name;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(Stri
parent label1.3. 0. M2Finally add the module dependency can beAs for the use of the module, as long as the dependency is written in the line, do not need other special action, use the example click here to have a video show, or pretty clear.Pay special attention to Because the inheritance of the Pom.xml version is 1.3.0.m2, the original dependent on the inside if you omit version, but in the 1.3.0.m2 without the module will be error, this time only need to manually add the dependent version co
We are in the Web project, have encountered 404,405,500 such error message, need to handle the exception information,
Launch the app, access a nonexistent URL, or modify the processing to throw an exception directly, such as:
1
@RequestMapping ("/hello")
2
Public String Hello () throws Exception {
3
throw new Exception ("error occurred");
4
}
The
We have encountered 404,405,500 of these error messages in our Web project, and we need to handle exception information.
Start the application, access a non-existent URL, or modify the processing content to throw an exception directly, such as:
1
@RequestMapping ("/hello")
2
Public String Hello () throws Exception {
3
throw new Exception ("error occurred");
4
------Error Handling mechanism------Default effect1 Returns a default error pageThe client responds to JSON data by defaultPrinciple: Automatic configuration with reference to errormvcautoconfiguration errorDefaulterrorattributesBasicerrorcontrollerErrorpagecustomizerDefaulterrorviewresolverSteps:Once the system has an error: Errorpagecustomizer effective (custom error response rule)2 How to customize the error response1) Custom error page2) Custom JSON error data
The Web Development Rendering page of Spring boot Learning (iv) was written in the previous article--Freemarker
Next, let's talk about velocity integration, which is the same as Freemarker, no big difference .
Here's a look at Pol. The jar introduced by XML
Need to
1
2
3
In the previous article, we talked about single data connection access, inserting data, but often as the traffic grows, we usually split the database or introduce other databases, so we need to configure multiple data sources, The configuration of two multi-data sources is described below, based on the previous jdbctemplate and SPRING-DATA-JPA examples.
See the jar referenced by the pom file first
XML version= "1.0" encoding= "UTF-8"?> Project xmlns=
The Spring boot hit jar POM configuration is as follows: note Spring-boot-maven-plugin version problem
My development tool is using idea click Maven Project to find the input Maven command window as follows:
Click the button above with M to enter:
Clean:clean PACKAGE-DMAVEN.TEST.SKIP=TRUE-E
Locate the jar in th
1. Project The Main method class is the project that launches the class startup project itself integrated Tomcat2.Controller Control LayerConfiguration Files Application.yml DataSource and JPA are equivalent to public configurationAssignment of a class3.AOP and spring AOP are pretty much the same XML that doesn't need to be configured4. Unified exception handling unification is the same formatThis exception is thrown directly on the controller to call
It takes only two steps to replace the default Web container in Springboot as jetty
Step One: Remove the default tomcat dependencies in the Springboot.
Step Two: Add jetty dependencies.
Completing the POM file:
Project Launch results show:
---: jetty-9.4.7.v20170914
---: Defaultsessionidmanager workername=node0
---: No sessionscavenger set, using D Efaults
---: scavenging every 660000ms
---: Initializing Spr
The test file can be automatically generated in the class file by right-->go to->test1. Add Test NotesSimple method Test@RunWith (Springrunner.class)@SpringBootTestpublic class Girlservicetest { @Autowired Private Girlservice Girlservice; @Test public void FindOne () throws Exception { Girl Girl = Girlservice.findone (30); Assert.assertequals (New Integer, Girl.getage ()); Assertion }}RESTAPI Test@RunWith (Springrunner.class)@SpringBootTest@AutoConfigureMockMvcpublic
We have experienced a simple RESTful API development service;
To load static resource access
When we develop Web applications, we need to cite a large number of JS, CSS, pictures and other static resources.
Default configuration
Spring boot defaults to provide static resource directory locations that need to be placed under Classpath, and directory names should c
When we are doing Web applications, it is very common for errors to occur during request processing. Spring Boot provides a default mapping: When an exception is thrown in processing, it is /error forwarded to the request for processing, and the request has a global error page to display the exception content.Choose a previously implemented
The Web Development Rendering page of Spring boot Learning (iv) was written in the previous article--Thymeleaf
Next, let's take a look at Freemarker integration Springboot
See controller:
@RequestMapping ("/") public
String index (Modelmap map) {
map.addattribute ("name", "Xiao Jin gg");
Return "index";
}
Pom.xml introduced:
Write a
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.