首页 新闻 会员 周边 捐助

idea找不到主类

0
悬赏园豆:10 [已解决问题] 解决于 2024-05-19 10:47

问一下大佬们显示找不到加载不了主类的原因:
具体图片如下:

项目结构配置如下:

同时主类

源:
路径:

问一下大佬是什么原因:感激不禁

0o_O_o0的主页 0o_O_o0 | 初学一级 | 园豆:133
提问于:2024-05-16 17:31
< >
分享
最佳答案
1

朋友你为啥不放到最外层呢?不然怎么扫描到组件呢?放到第一个spring目录下不行吗

收获园豆:10
信念是基石心学Plus版 | 初学一级 |园豆:140 | 2024-05-17 08:55

放在第一个spring下会报错了

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 08:56

@0o_O_o0: 报什么错?

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 08:59

@0o_O_o0: 结构截图我看看

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 08:59

@0o_O_o0:
一般结构是这样的

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 09:00

@戒吧老哥助我一臂之力:

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 09:06

@戒吧老哥助我一臂之力:
换到spring下就这样了:

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 09:07

@戒吧老哥助我一臂之力:

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 09:09

@0o_O_o0: 第三行

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 09:47

@戒吧老哥助我一臂之力:

换完了之后会这样,大佬看看有什么解决办法吗

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 10:11

@0o_O_o0:
不是,朋友。你在这个文件中引入 BootApplication 这个文件?SpringBoot的注解会自动扫描一个包下面的所有组件,不要你引入这个文件阿。放那里就可以了,不需要别的地方引入这个Java

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 11:13

@戒吧老哥助我一臂之力:
但是删除掉引入后QueryConnection文件内使用BootApplication还是会爆红

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 11:17

@0o_O_o0: 不是你QueryConnection文件为啥要用BootApplication 我表示有点费解

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 13:32

@戒吧老哥助我一臂之力:
dak
弄好了,但是在spring下还是出现错误

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 13:34

@0o_O_o0: 报错截图和相关代码截图呢?

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 13:47

@戒吧老哥助我一臂之力:


麻烦大佬给看一下

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 14:10

@0o_O_o0: 代码截图呢?看这个看不出来什么哦

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 14:45

@戒吧老哥助我一臂之力:

有没有错呢

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 14:59

@0o_O_o0: extends SpringBootServletInitializer 继承这个类

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:12

@戒吧老哥助我一臂之力:

大佬,是这样吗

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 15:19

@0o_O_o0: 你试试

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:20

@戒吧老哥助我一臂之力:
还是不可以

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 15:22

@0o_O_o0: 所以有什么报错或者截图呢?

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:23

@戒吧老哥助我一臂之力:
这是详细的错误:
错误: 找不到或无法加载主类 com.spring.BootApplication
原因: java.lang.ClassNotFoundException: com.spring.BootApplication
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.326 s
[INFO] Finished at: 2024-05-17T15:24:57+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.8.RELEASE:run (default-cli) on project BootApplication: Could not exec java: Application finished with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.8.RELEASE:run (default-cli) on project BootApplication: Could not exec java
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not exec java
at org.springframework.boot.maven.RunMojo.runWithForkedJvm (RunMojo.java:83)
at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm (AbstractRunMojo.java:276)
at org.springframework.boot.maven.AbstractRunMojo.run (AbstractRunMojo.java:240)
at org.springframework.boot.maven.AbstractRunMojo.execute (AbstractRunMojo.java:199)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: Application finished with exit code: 1
at org.springframework.boot.maven.RunMojo.runWithForkedJvm (RunMojo.java:80)
at org.springframework.boot.maven.AbstractRunMojo.doRunWithForkedJvm (AbstractRunMojo.java:276)
at org.springframework.boot.maven.AbstractRunMojo.run (AbstractRunMojo.java:240)
at org.springframework.boot.maven.AbstractRunMojo.execute (AbstractRunMojo.java:199)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 15:25

@0o_O_o0: BootApplication 类名改一下不要用这个。前面加My或者是其他的

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:33

@0o_O_o0: 用pom.xml中用mainClass 指定main方法

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:35

@戒吧老哥助我一臂之力:
大佬看下:
还是不行

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 15:47

@0o_O_o0:
正常能进的,还有包名有空也换一个吧别com.spring了.XXX也行

信念是基石心学Plus版 | 园豆:140 (初学一级) | 2024-05-17 15:50

@戒吧老哥助我一臂之力:
大佬,我把spring下新建一个spring文件夹,把启动类放在该文件夹下,pom就转到该类,但是运行的时候还是出现一样的错误找不到启动类:

0o_O_o0 | 园豆:133 (初学一级) | 2024-05-17 17:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册