Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build the entry Program for SpringBoot

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to build the SpringBoot starter program". In the daily operation, I believe many people have doubts about how to build the SpringBoot starter program. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to build the SpringBoot starter program". Next, please follow the editor to study!

1. SpringBoot introduction:

With the popularity of dynamic languages (Ruby,Groovy,Scala,Node.js), the development of Java is particularly cumbersome, various configurations, low development efficiency, complex deployment processes and third-party technology integration is difficult.

In the above environment, SpringBoot came into being. It uses the concept of "habit due to configuration" to get the project up and running quickly. Using SpringBoot, it is easy to create a stand-alone project running (running jar with embedded Servlet containers) based on the Spring framework at the quasi-production level, using SpringBoot with little or no Spring configuration.

2. Core features of SpringBoot:

(1) you can run it independently in the form of a jar package, and you only need to run a SpringBoot project through the

Java-jar xx.jar to run

(2) embedded Servlet container, SpringBoot can choose Tomcat, Jetty or Undertow, so there is no need to deploy the project in the form of war package

(3) simplify Maven configuration. SpringBoot provides a series of start pom to simplify the dependency loading of Manen.

(4) SpringBoot automatically configures Bean for the classes in the jar package according to the jar packages and classes in the classpath, which greatly reduces the configuration we need to use.

(5) SpringBoot provides monitoring of runtime projects based on http,ssh,telnet.

(6) it is realized not by code generation, but by conditional annotations, which is also a new feature of Spring4.x. All configurations of Spring can be implemented without any xml configuration.

3. Build the first SpringBoot starter:

Org.springframework.boot

Spring-boot-starter-parent

1.5.6.RELEASE

Org.springframework.boot

Spring-boot-starter-web

Org.apache.maven.plugins

Maven-compiler-plugin

1.8

1.8

4. Enable automatic configuration

EnableAutoConfiguration: using this annotation on the startup class causes SpringBoot to automatically configure the project's configuration items based on the jar package on which the project depends. For example, if we add spring-boot-starter-web dependencies, SpringMVC dependencies will be introduced into the project, and SpringBoot will automatically configure Tomcat and SpringMVC.

5. Turn off automatic configuration:

Use the following comments on the startup class:

@ EnableAutoConfiguration (exclude = {RedisAutoConfiguration.class})

6. Custom banner:

1) Open the website:

Http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20

2) copy the generated characters into a text file, name the file banner.txt, and copy the banner.txt to the resources directory of the project

3) copy banner.txt to the resources directory of the project

7. Global profile:

The Spring Boot project uses a global configuration file application.properties or application.yml. Under the resources directory or / config under the classpath, we usually put it under resources.

Modify the port of tomcat to 8088:

8. Starter pom:

SpringBoot provides us with starter pom for enterprise-level development of most scenarios. As long as we use the starter pom required for application scenarios, the relevant technical configuration will disappear, and we can get the automatic configuration Bean provided by SpringBoot.

9. Read the custom configuration from application.properties:

(1) Custom properties in the application.properties file, such as

Book.author = Zhang San

Book.name = springboot

(2) use @ Value ("${book.author}") to get the value of the custom attribute

10. Read multiple custom attributes from application.properties, type-safe configuration:

Using @ Value to inject each custom configuration is troublesome in the project. When there are many custom properties, you need to inject it many times.

SpringBoot also provides a type-safe configuration method, which uses @ ConfigurationProperties to associate attributes in properties with attributes in a Bean, thus realizing type-safe configuration.

(1) Custom properties in the application.properties file: for example

Book.author = Zhang San

Book.name = springboot

(2) @ ConfigurationProperties (prefix= "book"). Note that you need to write the get set method in the Bean file.

At this point, the study on "how to build the entry program for SpringBoot" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report