In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 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: 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.