首页 > 其他分享 >IDEA社区版(IDEA Community Edition)创建Springboot父子项目

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

时间:2024-05-14 17:57:16浏览次数:13  
标签:Springboot spring boot IDEA springframework idea Community org 21

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 =)要取消排除数据源:

 

标签:Springboot,spring,boot,IDEA,springframework,idea,Community,org,21
From: https://www.cnblogs.com/lgg20/p/18191720

相关文章

  • 【SpringBoot】实现项目启动后执行的两个接口ApplicationRunner和CommandLineRunner
    开发中可能会有这样的场景,需要在容器启动的时候执行一些内容。比如读取配置文件,数据库连接之类的。SpringBoot给我们提供了两个接口来帮助我们实现这种需求。两个启动加载接口分别是:CommandLineRunner和ApplicationRunner。Spring提供了接口InitializingBean,jdk提供了@PostCo......
  • 【转】[IDEA] 启动报错 Internal error. Please refer to...
    转自:https://blog.csdn.net/liyh722/article/details/136699609 问题原因:java.net.BindException:地址已在使用中:也就是idea启动时需要占用一些端口,但是已经被其它打开的软件占用了。IDE正在本地主机上启动服务器,它将尝试在6942和6991之间的第一个可用端口上进行绑定,如果IDE......
  • idea jprofiler内存快照分析
    1、idea按照jprofiler插件setting->plugins->marketplace搜索jprofiler,安装并重启2、分析dump文件dump内存快照方式:jmap-dump:format=b,file=heapdump.phrof{jvm的pid}使用jprofiler导入dump文件导入成功3、jprofiler工具关注“BiggestObjects”、"GCroots"、"Packa......
  • springboot+vue创建_1
    Springboot+vue创建一、创建后台项目1.在文件夹创建一个空文件夹,在idea中打开它2.可以先修改一下file-->settings-->Maven里面的一下东西,改成自己的maven地址(以免后面pom.xml文件有问题)3.在sb_vue_mo中右键-->new-->Module,选择SpringInitializer之后自行修改我是选择了ja......
  • 记录一次Springboot Data Jdbc的autoWorkController异常
    Errorcreatingbeanwithname'autoWorkController':Unsatisfieddependencyexpressedthroughfield'jdbcRouteRepository':Errorcreatingbeanwithname'jdbcRouteRepository'definedincom.chint.infrastructure.repository.jdbc......
  • Springboot+React实现Minio文件分片上传、断点续传
    前言本文采用前后端结合,后端给前端每个分片的上传临时凭证,前端请求临时url,通过后端间接的去上传分片。其实无关乎vue或者react,思路都是一样的,逻辑也全都是js写的,跟模板语法或者jsx也没关系,仅仅是赋值不一样而已。前端:React+TypeScript+Antd+axios+spark-md5+p-......
  • 程序员的AI编程小助手,CodeGeeX在vscode,vs2022,IDEA2023使用体验总结
    程序员的AI编程小助手,CodeGeeX使用体验总结一、1.CodeGeeX是什么?能做什么?CodeGeeX是一个智能编程软件工具,目前CodeGeeX支持多种主流IDE,如VSCode、visualstudio2022,IntelliJIDEA、PyCharm、Vim等,同时,支持Python、Java、C++/C、JavaScript、Go等多种语言。CodeGeeX如何......
  • springboot文件上传下载到本机服务器上
    这次的文件上传下载仅指的是本机的服务器,不指第三方文件存储系统!!!1.在pom中加入以下依赖,如已经加入,请忽略<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <depende......
  • idea拉取代码认证失败重新登录
    一、背景在更改了github登录密码后,在本地idea的代码无法正常拉取,显示认证失败却没有弹出重新认证入口。二、目标idea在认证失败之后能够自动弹出认证窗口,进行重新认证。三、实现1、先删除存留在本地的github普通凭据,路径在控制版面→用户账户→凭据管理器下的管......
  • springboot项目启动会报4个加载不到的debug提示,可改可不改
    1.因为启动的时候会报提示:UnabletolocateLocaleResolverwithname'localeResolver':usingdefault[org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@17162122]有4个这样的--Resolver,(具体每个Resolver在下面注释有说明)要想不报这个加载提示,如果用不......