赞
踩
从一开始便在搭建好的框架中编写着代码,对整个项目的从0到1的搭建起来一直保持着好奇心。经过了几番折腾最终从0到1搭建完成,便用这第一篇博客,记录下最近如何从无到有搭建起项目的基础框架的
不勾选任何选项直接NEXT
删除src目录,除了parent Module删除src外,其他子Module都不能删除src。
创建parent Module完成
依然是选择Maven,然后什么都不勾选
这里因为连不上上面的地址,修改成了阿里的地址
这里什么也不勾选,直接Next
接着删除mvn相关东西
到这里,新Module创建完毕,准备配置各pom.xml
<?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"> <!-- parent指明继承关系,给出被继承的父项目的具体信息--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <!-- 父模块打包类型必须为pom --> <packaging>pom</packaging> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>hello</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>hello-dao</module> <module>hello-facade</module> <module>hello-service</module> </modules> <!-- 版本号统一管理 --> <dependencyManagement> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>hello-service</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>hello-facade</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>hello-dao</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </dependencyManagement> </project>
<?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">
<parent>
<artifactId>hello</artifactId>
<groupId>com.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hello-dao</artifactId>
</project>
<?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"> <parent> <artifactId>hello</artifactId> <groupId>com.example</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>hello-facade</artifactId> <!-- facade层依赖dao层,添加依赖 --> <dependencies> <dependency> <groupId>com.example</groupId> <artifactId>hello-dao</artifactId> </dependency> </dependencies> </project>
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>hello</artifactId> <groupId>com.example</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>hello-service</artifactId> <name>hello-service</name> <description>Demo project for Spring Boot</description> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.example</groupId> <artifactId>hello-facade</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.7.RELEASE</version> <configuration> <mainClass>com.example.helloservice.HelloServiceApplication</mainClass> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
package com.example.helloservice.impl; import com.example.hello.dao.Student; import com.example.hello.facade.StudyService; import org.springframework.stereotype.Service; @Service public class StudyServiceImpl implements StudyService { @Override public void testStudy() { Student student = new Student(); student.setName("张三"); student.setAddress("xxx"); student.setAge("18"); System.out.println("---"+student.toString()); } }
package com.example.helloservice.web; import com.example.hello.facade.StudyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class TestController { @Autowired StudyService studyService; @ResponseBody @GetMapping("/testStudy") public void testStudy() { studyService.testStudy(); } }
页面请求触发
执行成功
参照过多篇文章,最后找出了一个相对更简单的方式去创建多模块的springboot,不能直接原封不动的照搬别人的,最起码还是希望稍微比他人的再好那么点点,追求优解的路不停息。
1、谁再把IDEA的Project比作Eclipse的Workspace,我就跟谁急
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。