idea启动main函数 显示 “错误: 找不到或无法加载主类 com.Main Process finished with exit code 1”

本文分享了解决IDEA中因多个main方法导致的主类加载失败问题的经验,通过删除多余的main方法及其引用解决了错误。

idea项目之前都是好好的,但是第二天运行main方法就出现

“错误: 找不到或无法加载主类 com.Main Process finished with exit code 1”

用的Debug运行也显示这个,但还多两行代码。

网上搜索了发现不少有关解决这个问题的文章,包括什么修改地址,项目名字,方法名字,清理缓存之类的;也做了相应修改,还是无济于事。最后对比了同事的项目发现右边红色区域多了很多个main(这是被我删除后的样子,之前有main1,main2,main3一直到main6).且主main还依赖着其他main,开始尝试将除main外的所有main删掉,但是点击apply的时候回出现引用错误,保存不了,这时候需要打开main,里面涉及到对其他main的引用,删除这些引用解决了问题。

第一次用idea,用了一上午才解决这个问题,具体原因不得而知,希望能帮到大家,一起少踩坑。

 

D:\java8\bin\java.exe "-javaagent:D:\IntelliJ IDEA 2024.1.7\lib\idea_rt.jar=52236:D:\IntelliJ IDEA 2024.1.7\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\liguanghui\AppData\Local\Temp\classpath1434842385.jar com.example.hive.DDL_hive Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.slf4j.Log4jLoggerFactory: method <init>()V not found at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:53) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:41) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:142) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:121) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:332) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:284) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305) at org.apache.hadoop.conf.Configuration.<clinit>(Configuration.java:227) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.apache.spark.util.SparkClassUtils.classForName(SparkClassUtils.scala:41) at org.apache.spark.util.SparkClassUtils.classForName$(SparkClassUtils.scala:36) at org.apache.spark.util.Utils$.classForName(Utils.scala:94) at org.apache.spark.sql.SparkSession$.hiveClassesArePresent(SparkSession.scala:1332) at org.apache.spark.sql.SparkSession$Builder.enableHiveSupport(SparkSession.scala:1033) at com.example.hive.DDL_hive.main(DDL_hive.java:13) Process finished with exit code 1 package com.example.hive; import lombok.val; import org.apache.spark.sql.SparkSession; public class DDL_hive { public static void main(String[] args) { System.setProperty("HADOOP_USER_NAME", "root"); val orCreate = SparkSession .builder() .enableHiveSupport() .appName("spark_hive") .config("hive.metastore.uris", "thrift://192.168.2.199:9083") .master("local[*]") .config("spark.sql.catalogImplementation", "hive") // 移除以下两行配置 // .config("spark.sql.hive.metastore.version", "3.1.3") // .config("spark.sql.hive.metastore.jars", "builtin") .getOrCreate(); System.out.println("++++++++++++++++++++++++"); orCreate.sql("show databases").show(); orCreate.sql("load data local inpath 'data/student.txt' into table itligh.student").show(); orCreate.close(); } }
最新发布
11-09
idea启动springboot项目报错;org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration$ServiceRegistryEndpointConfiguration': Unsatisfied dependency expressed through field 'registration'; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.client.serviceregistry.Registration' available: expected single matching bean but found 2: eurekaRegistration,consulRegistration 2025-05-27 13:58:16.934 default [main] INFO o.a.catalina.core.StandardService - Stopping service [Tomcat] 2025-05-27 13:58:17.012 default [main] WARN o.a.c.loader.WebappClassLoaderBase - The web applica[tion [api] appears to have started a thread named spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) java.lang.Thread.run(Thread.java:748) 2025-05-27 13:58:17.017 default [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat 2025-05-27 13:58:17.449 default [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener - Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-05-27 13:58:17.460 default [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - *************************** APPLICATION FAILED TO START *************************** Description: Field registration in org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration$ServiceRegis2025-05-27 13:58:17.012 default [main] WARN o.a.c.loader.WebappClassLoaderBase - The web applica[tion [api] appears to have started a thread named spring.cloud.inetutils] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.misc.Unsafe.park(Native Method) java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) java.lang.Thread.run(Thread.java:748) 2025-05-27 13:58:17.017 default [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat 2025-05-27 13:58:17.449 default [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener - Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-05-27 13:58:17.460 default [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - tryEndpointConfiguration required a single bean, but 2 were found: - eurekaRegistration: defined in BeanDefinition defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class] - consulRegistration: defined by method 'consulRegistration' in class path resource [org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationAutoConfiguration.class] Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed 25-05-27@13:58:17 INFO - [DUBBO] Run shutdown hook now., dubbo version: 2.0.0.SR1, current host: 127.0.0.1 25-05-27@13:58:17 INFO - [DUBBO] Close all registries [], dubbo version: 2.0.0.SR1, current host: 127.0.0.1 Process finished with exit code 1
05-28
C:\Users\lijw0\.jdks\corretto-1.8.0_442\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:45918,suspend=y,server=n -javaagent:C:\Users\lijw0\AppData\Local\JetBrains\IntelliJIdea2025.1\captureAgent\debugger-agent.jar=file:///C:/Users/lijw0/AppData/Local/Temp/capture4886985102263896140.props -agentpath:C:\Users\lijw0\AppData\Local\Temp\idea_libasyncProfiler_dll_temp_folder1\libasyncProfiler.dll=version,jfr,event=wall,interval=10ms,cstack=no,file=C:\Users\lijw0\IdeaSnapshots\sdsEHSApplication_2025_11_06_103420.jfr,dbghelppath=C:\Users\lijw0\AppData\Local\Temp\idea_dbghelp_dll_temp_folder\dbghelp.dll,log=C:\Users\lijw0\AppData\Local\Temp\sdsEHSApplication_2025_11_06_103420.jfr.log.txt,logLevel=DEBUG -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Ddebugger.agent.enable.coroutines=true -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -Dfile.encoding=UTF-8 -classpath "D:\JavaSoftWare\IntelliJ IDEA 2025.1\lib\idea_rt.jar" com.intellij.rt.execution.CommandLineWrapper C:\Users\lijw0\AppData\Local\Temp\idea_classpath846579415 com.sdsEHS.sdsEHSApplication Connected to the target VM, address: '127.0.0.1:45918', transport: 'socket' . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.14) 10:34:24.321 [background-preinit] INFO o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.2.3.Final 10:34:24.326 [main] INFO c.s.sdsEHSApplication - [logStarting,55] - Starting sdsEHSApplication using Java 1.8.0_442 on DESKTOP-83AD4BH with PID 22380 (D:\SHProjects\sds_ehs\admin\target\classes started by lijw0 in D:\SHProjects\sds_ehs) 10:34:24.327 [main] DEBUG c.s.sdsEHSApplication - [logStarting,56] - Running with Spring Boot v2.5.14, Spring v5.3.20 10:34:24.327 [main] INFO c.s.sdsEHSApplication - [logStartupProfileInfo,686] - The following 1 profile is active: "test" 10:34:27.233 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'inComingMapper' and 'com.sdsEHS.restful.mapper.InComingMapper' mapperInterface. Bean already defined with the same name! 10:34:27.233 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'outComingMapper' and 'com.sdsEHS.restful.mapper.OutComingMapper' mapperInterface. Bean already defined with the same name! 10:34:27.234 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'testResultMapper' and 'com.sdsEHS.restful.mapper.TestResultMapper' mapperInterface. Bean already defined with the same name! 10:34:27.234 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'checkItemMapper' and 'com.sdsEHS.environmental.mapper.CheckItemMapper' mapperInterface. Bean already defined with the same name! 10:34:27.234 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'checkOrderMapper' and 'com.sdsEHS.environmental.mapper.CheckOrderMapper' mapperInterface. Bean already defined with the same name! 10:34:27.235 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'deviceAllMapper' and 'com.sdsEHS.environmental.mapper.DeviceAllMapper' mapperInterface. Bean already defined with the same name! 10:34:27.235 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'deviceMapper' and 'com.sdsEHS.environmental.mapper.DeviceMapper' mapperInterface. Bean already defined with the same name! 10:34:27.235 [main] WARN o.m.s.m.ClassPathMapperScanner - [warn,44] - Skipping MapperFactoryBean with name 'safetyHazardReviewRecordMapper' and 'com.sdsEHS.hazardManagement.mapper.SafetyHazardReviewRecordMapper' mapperInterface. Bean already defined with the same name! 10:34:28.925 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8000"] 10:34:28.926 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat] 10:34:28.926 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.63] 10:34:29.291 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext 10:34:30.359 [main] INFO org.redisson.Version - [logVersion,41] - Redisson 3.16.4 10:34:32.344 [redisson-netty-2-17] INFO o.r.c.p.MasterPubSubConnectionPool - [lambda$run$0,166] - 1 connections initialized for 127.0.0.1/127.0.0.1:6379 10:34:32.366 [redisson-netty-2-19] INFO o.r.c.p.MasterConnectionPool - [lambda$run$0,166] - 24 connections initialized for 127.0.0.1/127.0.0.1:6379 10:35:01.914 [main] INFO c.a.d.p.DruidDataSource - [init,972] - {dataSource-1} inited 10:35:01.977 [main] DEBUG c.s.s.m.S.selectConfigList - [debug,137] - ==> Preparing: select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config 10:35:02.123 [main] DEBUG c.s.s.m.S.selectConfigList - [debug,137] - ==> Parameters: 10:35:02.271 [main] DEBUG c.s.s.m.S.selectConfigList - [debug,137] - <== Total: 5 10:35:03.519 [main] DEBUG c.s.f.s.f.JwtAuthenticationTokenFilter - [init,242] - Filter 'jwtAuthenticationTokenFilter' configured for use 10:35:04.364 [main] DEBUG c.s.s.m.S.selectDictDataList - [debug,137] - ==> Preparing: select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark from sys_dict_data WHERE status = ? order by dict_sort asc 10:35:04.406 [main] DEBUG c.s.s.m.S.selectDictDataList - [debug,137] - ==> Parameters: 0(String) 10:35:04.518 [main] DEBUG c.s.s.m.S.selectDictDataList - [debug,137] - <== Total: 67 10:35:05.558 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1220] - Using default implementation for ThreadExecutor 10:35:05.628 [main] INFO o.q.c.SchedulerSignalerImpl - [<init>,61] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 10:35:05.628 [main] INFO o.q.c.QuartzScheduler - [<init>,229] - Quartz Scheduler v.2.3.2 created. 10:35:05.641 [main] INFO o.q.s.RAMJobStore - [initialize,155] - RAMJobStore initialized. 10:35:05.645 [main] INFO o.q.c.QuartzScheduler - [initialize,294] - Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'NON_CLUSTERED' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. 10:35:05.645 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1374] - Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance. 10:35:05.645 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1378] - Quartz scheduler version: 2.3.2 10:35:05.645 [main] INFO o.q.c.QuartzScheduler - [setJobFactory,2293] - JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@1e3a2177 10:35:05.703 [main] DEBUG c.s.q.m.S.selectJobAll - [debug,137] - ==> Preparing: select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark from sys_job 10:35:05.704 [main] DEBUG c.s.q.m.S.selectJobAll - [debug,137] - ==> Parameters: 10:35:05.736 [main] DEBUG c.s.q.m.S.selectJobAll - [debug,137] - <== Total: 5 10:35:06.158 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - [refresh,591] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'safetyHazardReviewRecordController': Unsatisfied dependency expressed through field 'safetyHazardReviewRecordService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'safetyHazardReviewRecordServiceImpl': Unsatisfied dependency expressed through field 'redisPlanNumberGenerator'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisPlanNumberGenerator' defined in file [D:\SHProjects\sds_ehs\HazardManagement\target\classes\com\sdsEHS\hazardManagement\util\RedisPlanNumberGenerator.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.redis.core.RedisTemplate<java.lang.String, java.lang.Object>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 10:35:06.158 [main] INFO o.q.c.QuartzScheduler - [shutdown,666] - Scheduler quartzScheduler_$_NON_CLUSTERED shutting down. 10:35:06.159 [main] INFO o.q.c.QuartzScheduler - [standby,585] - Scheduler quartzScheduler_$_NON_CLUSTERED paused. 10:35:06.159 [main] INFO o.q.c.QuartzScheduler - [shutdown,740] - Scheduler quartzScheduler_$_NON_CLUSTERED shutdown complete. 10:35:06.160 [main] INFO sys-user - [shutdownAsyncManager,31] - ====关闭后台任务任务线程池==== 10:35:06.168 [main] WARN o.s.c.a.CommonAnnotationBeanPostProcessor - [postProcessBeforeDestruction,185] - Destroy method on bean with name 'shutdownManager' threw an exception: java.lang.ExceptionInInitializerError 10:35:06.173 [main] INFO c.a.d.p.DruidDataSource - [close,2051] - {dataSource-0} closing ... 10:35:06.174 [main] INFO c.a.d.p.DruidDataSource - [close,2051] - {dataSource-1} closing ... 10:35:06.186 [main] INFO c.a.d.p.DruidDataSource - [close,2124] - {dataSource-1} closed 10:35:06.247 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat] 10:35:06.252 [main] WARN o.a.c.l.WebappClassLoaderBase - [log,173] - The web application [ROOT] appears to have started a thread named [Thread-18] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: sun.net.dns.ResolverConfigurationImpl.notifyAddrChange0(Native Method) sun.net.dns.ResolverConfigurationImpl$AddressChangeListener.run(ResolverConfigurationImpl.java:144) 10:35:06.323 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - [report,40] - *************************** APPLICATION FAILED TO START *************************** Description: Parameter 0 of constructor in com.sdsEHS.hazardManagement.util.RedisPlanNumberGenerator required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration. Disconnected from the target VM, address: '127.0.0.1:45918', transport: 'socket' Process finished with exit code 1
11-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值