背景:
今天练习SpringBoot的时候,创建了一个maven项目,该项目由一个父模块和两个子模块组成
下面放一下pom文件
Shiro的 pom
<?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>
<groupId>com.xilo</groupId>
<artifactId>shiro-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>shiro-java</module>
<module>shiro-spring</module>
</modules>
</project>
shiro-java 的 pom ,shiro-java是个普通的JaveSE的模块
<?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>
<groupId>com.xilo</groupId>
<artifactId>shiro-java</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.xilo</groupId>
<artifactId>shiro-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
</project>
shiro-spring 的pom,shiro-spring是个SpringBoot的模块
<?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>
<groupId>com.xilo</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.xilo</groupId>
<artifactId>shiro-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<!-- springframework-->
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
调整好项目结构之后,我打算启动下shiro-spring项目,然后就报错了
springboot错误: 找不到或无法加载主类
接着我打开项目结构(File -> Project Structure)瞎捣腾了一番之后就解决了
原因是我在父模块中给两个子模块标注了文件类型(看到五颜六色的文件就是被标注过的了)
同时,我又在外层给子模块标注了文件类型
导致发生了冲突,运行的时候编译器不知道去哪里找启动类,所以不要在父模块里给子模块的文件进行标准,要单独在子模块里标注
下面把父模块里的文件标注都取消就能把问题解决了