一直这个错误:

------------------------------------------------- 下面的方法试了,不行。。。
明明就在一个包里面的类,引用的时候都出现了红色错误,无法导入类。
或者其他的不可思议的错误。
可以试试“清除缓存重启”:
第一步:菜单中选择file->invalidate caches / restart

第二步:在弹出框中选择Invalidate and Restart。idea关闭并且自动重启,重启后问题解决。

如果idea出现类似的不合逻辑的错误,很有可能是缓存导致,试试“清除缓存重启”!
----------------------------------------------------- 后面终于发现问题, 原来是 maven的打包问题, thin jar 打包成了 fat jar
下面的 jar 的大小, 明显不对, 怎么可能59M ? 明显是 fat jar 的节奏

去掉 spring-boot-maven-plugin 就可以引入了!
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.2</version>
<!-- <version>${spring-boot.version}</version>-->
<configuration>
<mainClass>com.test.sad.JavaGateApplication</mainClass>
<jvmArguments>-Xms256M -Xmx1024M -XX:+UseConcMarkSweepGC</jvmArguments>
<executable>true</executable>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
或者修改打包时候的资源寻找位置:
<build>
<resources>
<!--mvn打包时,加入mvn外的jar包-->
<resource>
<directory>lib</directory>
<targetPath>BOOT-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<!--java文件中的xml文件允许打进包中,这部分是mybatis文件-->
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!--这里打包的时候不打配置文件,因为这里的jar包仅供其他项目集成,应该在使用此jar的最外层加配置-->
<excludes>
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
</excludes>
</resource>
</resources>
...
通过 BOOT-INF/lib 就可以把 额外的jar 打包进来。
over !
浙公网安备 33010602011771号