IDEA社区版(IDEA Community Edition)创建Springboot父子项目

news/2024/9/22 5:32:07

1. 因为社区办不支持使用spring Spring Initializr 的方式创建项目, 但是我们可以考虑使用别的方式达到效果:

创建方式有3种:

第一种:使用https://start.spring.io/ 官方URL创建项目,再导入到 IDEA Community Edition(后面简称:ideaC)。具体使用自行百度。缺点:没办法自定义springboot的版本。

第二种:下载插件:Spring boot Assistant, 然后就可以按照商业版的方式创建。

第三种:也是我今天推荐使用的方式。用ideaC的方式来创建:

1. 创建父工程:

2. 右键父项目,新建第一个子模块idea-service:

3. 同样的方式再创建一个子项目idea-stub:

4. 修改父工程的pom文件,添加springboot-parent 依赖 及其你想添加的依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><packaging>pom</packaging><modules><module>idea-service</module><module>idea-stub</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.2</version><relativePath/></parent><groupId>org.example</groupId><artifactId>demo-IdeaC</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>
</project>

5. 查看idea-stub的依赖有没问题,因为我设计stub项目是为了暴露服务的,暂时不需要添加其他jar包:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.example</groupId><artifactId>demo-IdeaC</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>idea-stub</artifactId><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties></project>

6. 查看idea-service的依赖,主要是spring-web的jar包,这是主服务端,需要负责项目启动,还要添加IdeaDemoApplication 启动类:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.example</groupId><artifactId>demo-IdeaC</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>idea-service</artifactId><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- spring-boot启动相关依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>3.2.2</version></dependency></dependencies></project>
 6.1  还需要修改2个子项目的打包方式为jar,父工程确认为pom:
 
6.2: 添加IdeaDemoApplication 启动类,要修改ComponentScan()扫描的地方:
package org.example;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;@EnableAsync
@Configuration
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan({"org.example.*"})
public class IdeaDemoApplication {public static void main(String[] args) {SpringApplication.run(IdeaDemoApplication.class, args);}}

7.  如果不需要加载数据源的话,配置启动应用程序:

8. 结果:

9. 如果需要配置数据源的话,需要添加yml文件,@SpringBootApplication(exclude =)要取消排除数据源:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/31498.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

php查询结果汉字乱码解决方法

问题描述:使用php查询数据显示,显示的结果中所有汉字乱码问题及解决:这种情况是编码造成的,检查数据库及页面编码是否一致,也可在页面增加: header(Content-Type:text/html;charset=utf-8); 刷新后页面汉字显示正常,问题解决

设计模式学习(二)工厂模式——简单工厂模式

讨论设计模式中的简单工厂模式目录前言简单工厂模式简介示例优点缺点使用场景 前言 工厂模式是一种常用的设计模式,属于创建型模式之一。它的主要目的是为了解耦组件之间的依赖关系。通过使用工厂模式,系统中的具体类的实例化过程可以被抽象出来,从而使得系统更加模块化,增…

Pytest配置文件pytest.ini

pytest.ini 配置 pytest.ini 是什么pytest.ini 是 pytest 的配置文件 可以修改 pytest 的默认行为 不能使用任何中文符号,包括汉字、空格、引号、冒号等等pytest.ini修改用例的命名规则 配置日志格式,比代码配置更方便 添加标签,防止运行过程报警告错误 指定执行目录 排除搜…

使用ZXing.Net生成二维码

所需依赖组件 从工程安装的ZXing.Net Nuget包查看,ZXing.Net不依赖其他组件。查看package包内容,发现内部就zxing.dll和zxing.presentation.dll两个动态库文件。ZXing.Net生成的二维码形式 生成的二维码形式为内存Bitmap图像对象,如果需保存为文件或Base64字符串需另外书写代…

Netgear无线路由器漏洞复现(CVE-2019-20760)

本文复现的漏洞为Netgear路由器远程命令执行漏洞,1.0.4.26之前的NETGEAR R9000设备会受到身份验证绕过的影响,可利用漏洞将木马程序下载下来,获取 shell。漏洞概述 漏洞服务: uhttpd 漏洞类型: 远程命令执行 影响范围: 1.0.4.26之前的NETGEAR R9000设备会受到身份验证绕过…

经验分享:春招零Offer,5月份还有机会吗?

先说答案:5 月份依然有拿到 Offer 的机会。 5月份春招结束了吗?对于应届大学生来说(也就是今年暑假毕业的学生),5 月中旬春招就陆续结束了,但是 5 月份会有很多补录的机会。 对于非应届的大学生来说(今年之后毕业的学生)来说,5 月和 6 月正是在暑假最好的时机,尤其是…

PMS15

1. GPIO 相关的寄存器设置典型配置程序: //第一种配置方式 PA = 0b0110_0000; \ //设置数据 PAPH = 0b1110_0000; \ //设置上下拉 PAC = 0b1110_0000; \ //控制输入输出//第二种配置方式 PAC.4 = 0; …

探索大语言模型:理解Self Attention

一、背景知识 在ChatGPT引发全球关注之后,学习和运用大型语言模型迅速成为了热门趋势。作为程序员,我们不仅要理解其表象,更要探究其背后的原理。究竟是什么使得ChatGPT能够实现如此卓越的问答性能?自注意力机制的巧妙融入无疑是关键因素之一。那么,自注意力机制究竟是什么…