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

idea,community,edition,springboot · 浏览次数 : 6

小编点评

## 总结内容: 1. 使用ideaC创建项目时,可以选择3种方式: - 使用Spring Initializr创建项目,并导入到ideaC中 - 使用Spring Boot Assistant创建项目 - 自行创建项目,并添加springboot-parent依赖 2. 项目构建时,需要修改2个子项目的打包方式为jar,父工程确认为pom 3. 如果不需要加载数据源,配置启动应用程序 4. 如果需要配置数据源,需要添加yml文件,取消排除数据源 5. 以上内容需要带简单的排版

正文

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

 

与IDEA社区版(IDEA Community Edition)创建Springboot父子项目相似的内容:

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

1. 因为社区办不支持使用spring Spring Initializr 的方式创建项目, 但是我们可以考虑使用别的方式达到效果: 创建方式有3种: 第一种:使用https://start.spring.io/ 官方URL创建项目,再导入到 IDEA Community Edition(后面简称:

IDEA的Ctrl+Enter补全代码失效

## 前景提示 * IDEA有个ctrl+enter可以补全代码的功能,但是,今天突然失效了,原来是这个问题. ## 修改配置 * 进入setting修改 ![](https://img2023.cnblogs.com/blog/994129/202307/994129-20230721164840

IDEA工具第一篇:细节使用-习惯设置

安装好Idea后,直接上手clone代码进入编码时代,有没有那么一刻你会觉用起来没有那么顺手流畅呢? 👉👉👉 下面是关于 【Windows】 下安装idea的一些习惯设置👈👈👈【 Mac大致一样 】

idea构建grpc项目

转载请注明出处: 安装protocbuf插件 idea 建议下载一个 protobuf的插件, 可以有代码提示. 这里直接去pluging里搜就行了. 在idea的plugins中搜索proto,然后下载如下的插件就行(最多下载的那个),点击install,然后重启就可以。 gRPC项目构建 新建M

IDEA用上这十大插件绝对舒服

本文翻译自国外论坛 medium,原文地址:https://medium.com/@xjpp22/top-10-plugins-for-intellij-idea-you-dont-want-to-miss-38a723e26140 在本文中,我们将介绍 10 多个最好的 IntelliJ IDEA

EasyCode全自动单表增删改查!

需要IDEA下载EasyCode插件 准备好三个基础Base类 分页封装基础 package com.gton.io; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; imp

老问题了:idea中使用maven archetype新建项目时卡住

# 背景 作为一个后端Java打工人,idea就是最重要的打饭工具。创建项目,熟悉吧,但是,这么多年下来,因为idea换了版本,电脑换了等等,我还是时不时遇到根据maven archetype新建maven项目卡住。没错,我说的就是下面这样的场景: ![image-20230818220009447

Java -jar 运行 报 MalformedInputException: Input length = 1

Intellij IDEA 中运行正常,linux 运行正常, cmd 下运行 报:MalformedInputException: Input length = 1 微服务项目,在Nacos中做了配置,在引用 Nacos中配置时,编码问题,导致的错误 org.yaml.snakeyaml.erro

Intellij IDEA、 Pycharm 格式化换行,竖线修改

Intellij IDEA、 Pycharm 等开发工具,超过 竖线,Ctrl + L 格式化时,就会换行 , File -> Settings -> Editor -> Code Style -> Hard wrap at 值调整 ( 调到合适的值 )

Intellij IDEA 显示 access.log 日志

先配置 SpringBoot 记录 access.log 日志,先让accesslog 显示出来