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 customize the stater startup process using springboot

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use springboot to customize the stater startup process. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

When springboot starts, it automatically loads application.properties or application.yml. How to define its own configuration and let springboot automatically recognize it:

First, let's create a new maven project and select jar as the packaging method, and then introduce the required packages.

4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.6.RELEASE com.ruobbo.xxl ruobbo.xxl 0.0.1-SNAPSHOT jar 1.8 org.springframework.boot spring-boot-starter 2.1.6.RELEASE org.springframework.boot spring-boot-autoconfigure 2.1.6.RELEASE org.springframework.boot spring-boot-configuration-processor 2.1.6.RELEASE org.projectlombok lombok 1.18.8 provided com.xuxueli xxl-job-core 2.0.1 org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine releases http://192.168.1.99:8081/nexus/content/repositories/releases snapshots http://192.168.1.99:8081/nexus/content/repositories/snapshots

Then there is configuration reading.

@ ConfigurationProperties (prefix = "xxl.job.executor") @ Datapublic class XxlProperties {private String adminAddresses; private String appName; private String ip; private int port; private String accessToken; private String logPath; private int logRetentionDays; private String basePackages;}

The read configuration is injected into the bean and then loaded into the spring bean container

@ Configuration@EnableConfigurationProperties (XxlProperties.class) public class XxlAutoConfiguration {private Logger logger = LoggerFactory.getLogger (XxlAutoConfiguration.class); @ Resource private XxlProperties xxlProperties; @ Bean (initMethod = "start", destroyMethod = "destroy") public XxlJobSpringExecutor xxlJobExecutor () {logger.info ("> xxl-job config init."); XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor (); xxlJobSpringExecutor.setAdminAddresses (xxlProperties.getAdminAddresses ()); xxlJobSpringExecutor.setAppName (xxlProperties.getAppName ()); xxlJobSpringExecutor.setIp (xxlProperties.getIp ()); xxlJobSpringExecutor.setPort (xxlProperties.getPort ()) XxlJobSpringExecutor.setAccessToken (xxlProperties.getAccessToken ()); xxlJobSpringExecutor.setLogPath (xxlProperties.getLogPath ()); xxlJobSpringExecutor.setLogRetentionDays (xxlProperties.getLogRetentionDays ()); return xxlJobSpringExecutor;}}

Finally, add the META-INF folder under the resources directory and add the spring.factories file, which specifies the full path of the class to initialize springbean.

Org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.ruobbo.xxl.XxlAutoConfiguration

Introduce the package during use

Com.ruobbo.xxl ruobbo.xxl 0.0.1-SNAPSHOT

Then add the configuration to application.properties or application.yml

On "how to use springboot custom stater startup process" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

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: 244

*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

Development

Wechat

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

12
Report