Spring Boot is the best Java framework for microservices. We recommend you to become a Spring Boot expert.
Question one
What is the difference between Spring Boot, Spring MVC and Spring?
SpringFrame
The most important feature of SpringFramework is dependency injection. All SpringModules are either Dependency Injection or IOC Inversion of Control.
When we use DI or IOC properly, we can develop loosely coupled applications. Unit testing of loosely coupled applications can be done easily.
SpringMVC
Spring MVC provides a decoupled approach to developing web applications. By using some simple concepts like DispatcherServlet, MoudlAndView and ViewResolver, developing web applications will become very simple.
The problem with SpringBoot
Spring and SpringMVC is that a large number of parameters need to be configured.
/WEB-INF/views/
.jsp
<mvc:resources mapping="/webjars/**" location="/webjars/"/>
Copy
Spring Boot to solve this problem with an auto-configuration and startup project. To build production-ready applications faster, Spring Boot provides some non-functional features.
question two
What is auto-configuration?
The problem with Spring and SpringMVC is that there are a lot of parameters to configure.
/WEB-INF/views/.jsp <
mvc
:resources mapping="/webjars/**" location="/webjars/"/>
Copy
Can we bring more intelligence? Can we auto-configure some beans when an MVC JAR is added to the application?
Spring looks at (frameworks available on CLASSPATH ) the configuration of an existing application. On this basis, Spring Boot provides the basic configuration needed to configure the application and framework. This is automatic configuration.
question three
What is Spring Boot Stater?
A launcher is a convenient set of dependency descriptors that it can place in its own program. You get all the Spring and related technologies you need in one place, without the need to search through sample code and loads of copy-and-paste dependent descriptors.
For example, if you want to use Spring and JPA to access a database, you only need your project to include the spring-boot-starter-data-jpa dependency and you're good to go.
question four
Can you give an example to explain more about Staters?
Let's consider an example of Stater - Spring Boot Stater Web.
If you want to develop a web application or an application that exposes REST services. Spring Boot Start Web is preferred. Let's create a Spring Boot Start Web quick project using Spring Initializr.
Dependencies for Spring Boot Start Web
org.springframework.boot spring-boot-starter-web Copy The screenshots below are the different dependencies added to our applicationDependencies can be divided into
Spring - core,beans,context,aop
Web MVC - (Spring MVC)
Jackson - for JSON Binding
Validation - Hibernate,Validation API
Enbedded Servlet Container - Tomcat
Logging - logback,slf4j
Any classic web application uses all of these dependencies. Spring Boot Starter Web comes pre-packaged with these dependencies.
As a developer, I no longer need to worry about these dependencies and their compatible versions.
Question five
What other Starter Project Options does Spring Boot provide?
Spring Boot also provides other starter projects that include typical dependencies for developing a particular type of application.
spring-boot-starter-web-services - SOAP Web Services
spring-boot-starter-web - Web and RESTful applications
spring-boot-starter-test - unit and integration tests
spring-boot-starter-jdbc - Traditional JDBC
spring-boot-starter-hateoas - Adds HATEOAS functionality to services
spring-boot-starter-security - Authentication and authorization with SpringSecurity
spring-boot-starter-data-jpa - Spring Data JPA with Hibeernate
spring-boot-starter-data-rest - Expose simple REST services using Spring Data REST
question six
How does Spring quickly create production-ready applications?
Spring Boot is all about fast production-ready applications. To this end, it provides out-of-the-box non-functional features such as caching, logging, monitoring and embedded servers.
spring-boot-starter-actuator - use some advanced features like monitoring and tracing applications
spring-boot-starter-undertow, spring-boot-starter-jetty, spring-boot-starter-tomcat - choose your specific embedded Servlet container
spring-boot-starter-logging - Logging with logback
spring-boot-starter-cache - Enables Spring Framework's caching support
What is the minimum Java version required for Spring2 and Spring5?
Spring Boot 2.0 requires Java8 or later. Java6 and Java7 are no longer supported.
Recommended reading:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0.0-M1-Release-Notes
question seven
What's the easiest way to create a Spring Boot Project?
Spring Initializr is a great tool for starting Spring Boot Projects.
As shown in the figure above, we need to do a few steps:
log in to Spring Initializr, and select as follows:
select com.in28minutes.springboot as the group
, select studet-services as the component,
select the following dependencies, click
Web
Actuator
DevTools
Generate GenerateProject
to import the project into Eclipse. File - Import - Existing Maven Project
Question 8
Is Spring Initializr the only way to create Spring Boot Projects?
no.
Spring Initiatlizr makes it easy to create Spring Boot projects, however, you can also start a project by setting up a maven project and adding the correct dependencies.
In our Spring courses, we use two approaches to create projects.
The first method is start.spring.io.
Another method is to manually set it in the project titled "Basic Web Application".
Manually setup a maven project
Here are a few important steps:
In Eclipse, use File - New Maven Project to create a new project
and add dependencies.
Add maven plugin.
Add the Spring Boot application class.
Here, the preparations are done!
Question nine
Why do we need spring-boot-maven-plugin?
spring-boot-maven-plugin provides some commands for packaging or running applications like jars.
spring-boot:run runs your Spring Booty application.
spring-boot:repackage repackages your jar or war package to make it executable
spring-boot:start and spring-boot:stop manage the lifecycle of Spring Boot applications (also for integration testing).
spring-boot:build-info generates build information that the executor can use.
Question ten
How to automatically reload my application with SpringBoot?
Use Spring Boot development tools.
Adding the Spring Boot development tools to your project is simple.
Add the following dependencies to your Spring Boot Project pom.xml
org.springframework.boot spring-boot-devtools runtime Copy restart the application, then it's ok.Also, if you want to autoload pages, have a look at FiveReload
http://www.logicbig.com/tutorials/spring-framework/spring-boot/boot-live-reload/.
When I tested, I found the LiveReload vulnerability. If you also found it during the test, please tell us.
Question Eleven
What is an embedded server? Why should we use an embedded server?
Think about what it takes to deploy an application on your virtual machine.
Step 1: Install Java
Part 2: Install the Web or application server (Tomat/Wbesphere/Weblogic, etc.)
Part 3: Deploy the application war package
If we want to simplify these steps, how should we do it?
Let's think about how to make the server part of the application?
You only need a virtual machine with Java installed, and you can deploy applications directly on it,
isn't it cool?
This idea is the origin of embedded servers.
When we create a deployable application, we will embed the server (for example, tomcat) into the deployable server.
For example, for a Spring Boot application, you can generate an application jar that includes Embedded Tomcat. You can then run the web application as you would a normal Java application.
An embedded server is where our executable unit contains the server's binary (for example, tomcat.jar).
Question twelve
How to add common JS code in Spring Boot?
Under the source folder, create a folder named static. Then, you can put your static content in there.
For example, the path to myapp.js is resources\static\js\myapp.js
You can refer to how it is used in jsp
复制
错误:HAL browser gives me unauthorized error - Full authenticaition is required to access this resource.
How to fix this error?
{ "timestamp": 1488656019562, "status": 401, "error": "Unauthorized", "message": "Full authentication is required to access this resource.", "path": "/beans" } Copy two methods :
Method 1: Turn off security verification
application.properties
management.security.enabled: FALSE
Replication
Method 2: Search for the password in the log and pass it to the request header
Question 13
What is Spring Date?
From: //projects.spring.io/spring-data/
The mission of Spring Data is to provide a familiar, consistent, Spring-based programming model for data access while ensuring the specificity of the underlying data storage. This makes it easy to use data access technologies, relational and non-relational databases, map-reduce frameworks, and cloud-based data services.
To make it a little easier, Spring Data provides an Abstractions interface that is not restricted by the underlying data source.
Here's an example
interface TodoRepository extends CrudRepository<Todo, Long> { Copy You can define a simple library for inserting, updating, deleting and retrieving to-do items without writing a lot of code.