In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to build springboot framework". In daily operation, I believe many people have doubts about how to build springboot framework. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to build springboot framework". Next, please follow the editor to study!
First, configure Maven1. Download Maven
Apache-maven-3.6.1.zip
two。 Configure the local warehouse
Configure local warehouse apache-maven-3.6.1 > > conf > > settings.xml
3. Configuration of image repository
Since apache's remote repositories are abroad, the download speed of JAR packages is slow, so one or two image repositories can be configured (domestic).
Then click User Settings under Maven
two。 Create a project
File > > New > > Spring Start Project
Finsh
3. Version conflict problem
At this point, the pom.xml file of the project will report an error
Solution: add the version number of the maven.jar plug-in to the properties of the pom.xml file
3.1.1
4. Engineering catalogue
Yml and yaml files are the same, and finally ApplyClose.
6. Test whether the construction is successful or not
Find src/main/java > > com.hsiao > > MyspringbootApplication.java > > right click > > Run as > > Spring Boot App
Open Google browser > > address bar and enter localhost:8080
This interface represents the success of building!
III. Basic configuration information
Mainly the configuration of yml file (Note: properties asking price and yml file exist at the same time, properties file will be loaded)
1. Modify server port # overwrite service port (SpringBoot default embedded Web container) server: address: localhost port: 12342.JSP page storage directory
Create a new JSP storage page folder webapp under src/main
Create a new WEB-INF folder under the webapp folder
JSP interface storage path: / src/main/webapp/WEB-INF or / src/main/webapp/
3.pom.xml configuration JSP parsing Technology org.apache.tomcat.embed tomcat-embed-jasper provided 4.pom.xml configuration jsp tag Library javax.servlet jstl Compile5. Custom storage directory for static resources
Static resources load path public or static by default. If you need to customize the folder, you need to configure it in the configuration file.
Spring: mvc: static-path-pattern: / * * / * # static resource mapping path resources: static-locations:-classpath:/myresources # actual classpath 6. Hot deployment tool (devtools)
1.pom.xml file configuration jar package
Org.springframework.boot spring-boot-devtools true provided
two。 Configure in application.yml
Spring: # Engineering hot deployment configuration devtools: restart: enabled: true # Hot deployment does not load path exclude: src/main/resources/static # additional-exclude: exclude path # Hot deployment load path additional-paths:-src/main/java-src/main/webapp-src/main/resources/myresources7. Log record
Log level: off (off) > fatal (critical error) > error (error) > warn (warning) > info (information) > debug (debugging) > trace (very low log level) > all (open)
Slf4j is equivalent to a public interface, not the interface type log4j < logback < log4j2 in JAVA.
1.logback
Springboot uses logback by default
Private static Logger log=LoggerFactory.getLogger (current class name. Class); Note: all imported packages are under org.slf4j
Set which package and which level of log information to print in the application.yml configuration file
# configuration of logging logging: level: com: debug
Save the printed log information in a file and configure it in the application.yml configuration file
# configuration of logging logging: # path: # specify the storage path. By default, file: mylog.log # specify the file name file.max-size: 10MB # log file size level: com: debug2.spring boot integrated log4j under the project directory
First, remove the default logback from pom.xml and add log4j
Org.springframework.boot spring-boot-starter-log4j2 org.springframework.boot spring-boot-starter Org.springframework.boot spring-boot-starter-logging
Then add the configuration file of log4j under the root directory of resoures, and finally add the configuration of log in application.yml.
# logging: config: classpath:log4j2-spring.xml # plus custom log file configuration information # Note the default log configuration note 8. Customize the path to the configuration file
Suppose you put the application.yml or properties file under the custapplication folder
1.properties file
SpringApplication springApplication = new SpringApplication (MyspringbootApplication.class); / / application load configuration file Properties defaultProperties = new Properties (); try {defaultProperties.load (MyspringbootApplication.class. GetResourceAsStream ("/ custapplication/application.properties");} catch (IOException e) {/ / TODO Auto-generated catch block e.printStackTrace ();} springApplication.setDefaultProperties (defaultProperties); springApplication.run (args)
2.yml file
9. Change advertising banners
A website that generates art characters: https://www.bootschool.net/ascii
Copy the font to the banner.txt document, and then copy the document to the resource root directory
Close the advertising banner and add the following to application.perproties:
Spring.main.banner-mode= off IV, right out of the box
Create a new testController.java under src/main/java
Package com.hsiao;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class testController {@ RequestMapping ("/ hello") public String hello () {return "Hello word";}}
Open the browser address bar and enter http://localhost:8081/hello; the interface shows that Hello word represents success
At this point, the study on "how to build a springboot framework" 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.