In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Maven itself provides a lot of Archetypes to facilitate users to create projects, but each team may have some common files or configurations, in order to avoid duplication and modification when creating projects, we use custom Archetypes to standardize it is quite necessary, the following is a brief introduction to the use of maven-archetype-archetype to build their own Archetype process.
Create your own Archetype project
template
mvn archetype:generate \ -DarchetypeGroupId= \ -DarchetypeArtifactId= \ -DarchetypeVersion= \ -DgroupId= \ -DartifactId=
For example:
mvn archetype:generate \ -DgroupId=com.ultrapower.maven.archetypes \ -DartifactId=springboot-maven-archetype \ -DarchetypeArtifactId=maven-archetype-archetype \ -DinteractiveMode=false \ -X
1) pom.xml under springboot-maven-archetype is used to define the coordinates of archetype project like general maven project
2) springboot-maven-archetype/src/main/resources/archetype-resources All the files that define the project to be generated (prototype files)
3) Descriptors (metadata) for the skeleton are defined in springboot-maven-archetype/src/main/resources/META-INF/maven/archetype.xml, which lists all files contained in the archetype and classifies them.
Note: springboot-maven-archetype/pom.xml is as follows
4.0.0 com.ultrapower.maven.archetypes springboot-maven-archetype 1.0-SNAPSHOT Archetype - springboot-maven-archetype http://maven.apache.org2, Modify pom.xml under archetype-resources, Add the required configuration.
For example:
4.0.0 ${groupId} ${artifactId} ${version} jar ${artifactId} http://www.myorganization.org org.springframework.boot spring-boot-starter-parent 2.0.0.RELEASE UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web io.springfox springfox-swagger2 2.8.0 io.springfox springfox-swagger-ui 2.8.0 org.apache.commons commons-lang3 junit junit 3.8.1 test 3. Add the required files
For example:
Application. java
package ${package};import org.springframework.boot.Banner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;import org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration;import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;import org.springframework.boot.web.servlet.FilterRegistrationBean;import org.springframework.boot.web.servlet.ServletComponentScan;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.ComponentScan;@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, JmsAutoConfiguration.class })@ServletComponentScan@ComponentScan(basePackages = { "${package}" })public class Application { public static void main(String[] args) { SpringApplication app = new SpringApplication(Application.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); }}
CorsConfig.java
package ${package}.config.beanconfig;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.cors.CorsConfiguration;import org.springframework.web.cors.UrlBasedCorsConfigurationSource;import org.springframework.web.filter.CorsFilter;@Configurationpublic class CorsConfig { private CorsConfiguration buildConfig() { CorsConfiguration corsConfiguration = new CorsConfiguration(); // 1 Set access source address corsConfiguration.addAllowedOrigin("*"); // 2 Set Access Source Request Header corsConfiguration.addAllowedHeader("*"); // 3 Set access source request method corsConfiguration.addAllowedMethod("*"); return corsConfiguration; } @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); // 4 Configure cross-domain settings for interfaces source.registerCorsConfiguration("/** ", buildConfig()); return new CorsFilter(source); }}4, modify the architype.xml file
For example:
springboot-maven-archetype src/main/java/Application.java src/main/java/config/beanconfig/MvcConfig.java src/main/java/config/beanconfig/CorsConfig.java src/main/java/config/beanconfig/RestTemplateConfig.java src/main/java/config/beanconfig/Swagger2Config.java src/main/java/config/condition/Swagger2Condition.java src/main/resources/application.yml src/main/resources/application-dev.yml src/main/resources/application-prod.yml boot/control.sh boot/control.bat src/test/java/AppTest.java
The above is to list each file, you can also use wildcards to simplify the configuration, for example:
springboot-maven-archetype src/main/java/** /*.* **/*.* src/test/java/AppTest.java 5, Install architypemvn install6, Create a project using custom architype mvn architype:generate -DarchitypeGroupId =com.ultrapower.maven. architypes-DarchitypeArtifactId =springboot-maven-architype-DarchitypeVersion =1.0-SNAPSHOT -DgroupId=com.ultrapower.ioss -DartifactId= springboot-architype-test -X
Note: We can replace architype.xml with "architype-metadata.xml", the following content can achieve the same effect, but still recommend architype.xml
archetype-metadata.xml: src/main/java **/*.java src/main/resources **/*.* boot **/*.* src/test/java **/*.java src/test/resources **/*.*
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.