这个错误,在网上搜找了好久,说是什么jar包冲突,什么环境配置,我经过验证均是正确的,javac java java -version 都没问题,环境变量也OK,各种解释均没有能够解决我的问题,最后好一顿折腾,解决了

shiro 的测试方法

 package com.sharp.forward;

 import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;
import org.junit.Before;
import org.junit.Test; public class JavaShiroTest extends ShiroApplicationTests{ SimpleAccountRealm realm = new SimpleAccountRealm("simpleRealm");
@Before
public void add() {
realm.addAccount("张三", "123456");
} @Test
public void contextLoads() {
}
@Test
public void testAuthenticate() {
// 三要素,SecurityManager,subject,realm
DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
// SecurityManage设置realm与数据库或缓存相连接
defaultSecurityManager.setRealm(realm);
// SecurityUtils设置SecurityManager可以与主题subject相连接
SecurityUtils.setSecurityManager(defaultSecurityManager);
// 获取主题,并通过secutityUtil将securityManager和realm联系起来,
Subject subject = SecurityUtils.getSubject();
// 提交主题是通过token提交的
UsernamePasswordToken token = new UsernamePasswordToken("张三", "123456");
subject.login(token);
System.out.println("subject.isAuthenticated(): "+subject.isAuthenticated()); } }

在测试类里面的测试方法报错,

java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testAuthenticate], {ExactMatcher:fDisplayName=testAuthenticate(com.sharp.forward.JavaShiroTest)], {LeadingIdentifierMatcher:fClassName=com.sharp.forward.JavaShiroTest,fLeadingIdentifier=testAuthenticate]] from org.junit.internal.requests.ClassRequest@73c6c3b2
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

然后在主类中写了一个main查看是否报错

然后找解决办法,

说明首先,我是创建的springboot工程,创建的时候,因为之前选择版本的问题,出来的项目总不是完整的项目,需要修改版本,可能是这个原因导致的一些配置发生了变化,现在先看一下我的创建过程,我的项目都是自己搭建的私服

当出现不完整的项目的时候,就把项目的版本修改为适应的版本就可以出来了,可能是由于记忆了,

之前出现题目中的问题是运行其他项目中突然出现的,于是我仍然在同样的环境下建的项目但运行helloworld

就是main方法打印helloworld,控制台同样出现了错误:找不到或无法加载主类的提示,

最终解决办法是:先run build install 此时发现不能成功,提示用的是jre不是jdk,然后修改为jdk,再次运行一切都好了,

然后我再去创建项目,除了将https改为http外,其他的完整项目均能一次加载,不需要修改版本了。

这样解决了,

但是我又重新复现了一下这个问题,发现单单修改了这里有时候还不行,maven install 仍然报jre而不是jdk,同样又出现上述问题,于是我又修改如下地方

项目右键属性,下方修改为jdk,

再次 install 然后再去运行helloworld和测试,完美解决,看来还是jdk在作怪。

测试运行结果

junit变为绿条了

控制台打印结果如下

 16:41:35.128 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.sharp.forward.JavaShiroTest]
16:41:35.135 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
16:41:35.147 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
16:41:35.171 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.sharp.forward.JavaShiroTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
16:41:35.189 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.sharp.forward.JavaShiroTest], using SpringBootContextLoader
16:41:35.199 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.sharp.forward.JavaShiroTest]: class path resource [com/sharp/forward/JavaShiroTest-context.xml] does not exist
16:41:35.200 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.sharp.forward.JavaShiroTest]: class path resource [com/sharp/forward/JavaShiroTestContext.groovy] does not exist
16:41:35.200 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.sharp.forward.JavaShiroTest]: no resource found for suffixes {-context.xml, Context.groovy}.
16:41:35.201 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.sharp.forward.JavaShiroTest]: JavaShiroTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
16:41:35.284 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.sharp.forward.JavaShiroTest]
16:41:35.397 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\worksheet\shiro\target\classes\com\sharp\forward\ShiroApplication.class]
16:41:35.404 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.sharp.forward.ShiroApplication for test class com.sharp.forward.JavaShiroTest
16:41:35.538 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.sharp.forward.JavaShiroTest]: using defaults.
16:41:35.540 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
16:41:35.592 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
16:41:35.593 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
16:41:35.593 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@6e171cd7, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@402bba4f, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@795cd85e, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@59fd97a8, org.springframework.test.context.support.DirtiesContextTestExecutionListener@f5ac9e4, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@123ef382, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@dbf57b3, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@384ad17b, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@61862a7f, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@441772e]
16:41:35.596 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.596 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.598 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.598 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.672 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.672 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.676 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.676 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.677 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.682 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.690 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@9f116cc testClass = JavaShiroTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@12468a38 testClass = JavaShiroTest, locations = '{}', classes = '{class com.sharp.forward.ShiroApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@76b0bfab, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@2f943d71, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3e57cd70, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@5bcea91b], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
16:41:35.691 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.sharp.forward.JavaShiroTest]
16:41:35.691 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.sharp.forward.JavaShiroTest]
16:41:35.734 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1} . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE) 2019-03-02 16:41:36.379 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : Starting JavaShiroTest on litan with PID 18776 (started by litan in D:\worksheet\shiro)
2019-03-02 16:41:36.382 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : No active profile set, falling back to default profiles: default
2019-03-02 16:41:39.311 INFO 18776 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-03-02 16:41:39.904 INFO 18776 --- [ main] com.sharp.forward.JavaShiroTest : Started JavaShiroTest in 4.153 seconds (JVM running for 5.806)
2019-03-02 16:41:40.645 INFO 18776 --- [ main] a.s.s.m.AbstractValidatingSessionManager : Enabling session validation scheduler...
subject.isAuthenticated(): true
2019-03-02 16:41:41.163 INFO 18776 --- [ Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'

helloworld运行结果

参考https://www.cnblogs.com/fengan/p/5904445.html,重建project有时也可以解决

eclipse springboot运行helloworld错误: 找不到或无法加载主类 xxx.xxx.xxx的更多相关文章

  1. springboot项目上有个红叉,且ecplise没有自动编译项目,运行提示“错误: 找不到或无法加载主类”

    近期在做springboot项目,发现springboot项目上有个红叉但找不到哪个类报错,ecplise没有把项目自动编译,运行还提示“错误: 找不到或无法加载主类”,进入工作空间“项目\targe ...

  2. Eclipse 无法编译,提示“错误: 找不到或无法加载主类”

    jar包问题: 1.项目的Java Build Path中的Libraries中有个jar包的Source attachment指为了一个不可用的jar包, 解决办法是:将这个不可用的jar包remo ...

  3. zzw原创_cmd下带jar包运行提示 “错误: 找不到或无法加载主类 ”

    在windows下编译java,由于是临时测试一下文件,不想改classpath,就在命令行中用 -cp 或classpath引入jar包,用javac编译成功,便使用java带-cp 或classp ...

  4. maven打包 运行出现 错误: 找不到或无法加载主类 jar

    使用maven进行打包成jar包后 使用java -jar运行jar包 出现 错误: 找不到或无法加载主类 jar 主要是由于依赖没下载好,重新下载依赖 以及要在项目的pom.xml里面添加 < ...

  5. Myeclipse运行提示错误: 找不到或无法加载主类 test.test1 终极解决办法

    前提是代码没有问题 简单粗暴的解决办法: 重启电脑 解决办法2: 1.在控制台中点开“Problems”,查看里面的错误.如果是多个项目,可以将其他项目暂时关闭. 根据错误进行处理. 2.把项目cle ...

  6. eclipse 执行main方法 错误: 找不到或无法加载主类

    检查环境变量是否正确 JAVA_HOME JAVA的实际安装目录 CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\ ...

  7. 今天遇到一件开心事,在eclipse编写的代码在命令窗口中编译后无法运行,提示 “错误: 找不到或无法加载主类”

    java中带package和不带package的编译运行方式是不同的. 首先来了解一下package的概念:简单定义为,package是一个为了方便管理组织java文件的目录结构,并防止不同java文 ...

  8. springboot错误: 找不到或无法加载主类

    一:当在eclipse启动spring boot项目时出现问题: springboot错误: 找不到或无法加载主类 解决办法: 1,通过cmd命令行,进入项目目录进行,mvn clean instal ...

  9. mac 下 使用 java运行 class 文件 总是提示 “错误: 找不到或无法加载主类”的解决方法

    发现问题 切换到mac平台后,突然想写点程序运行在mac下,想到mac自带java,会方便好多.不过在这过程中遇到了麻烦: 总是提示 “错误: 找不到或无法加载主类” 工程结构 查了好久,终于找到原型 ...

随机推荐

  1. IIS7和IIS8环境下 ThinkPHP专用URL Rewrite伪静态规则

      这是适用于IIS7,IIS7.5,IIS8.0及以上的ThinkPHP的伪静态规则,把以下代码保存成web.config文件,放到FTP的web目录内即可. <?xml version=&q ...

  2. PLSQL报错: ORA-12170:TNS connect timeout occurred

    本人的问题已解决,先在安装oracle的服务器上黑窗口输入tnsping,提示说no listener,这是监听服务没有打开. 打开服务后还是不行,最后原因是服务器的网络有防火墙的问题,关掉防火墙连接 ...

  3. Jquery练习1

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. 明明的随机数(0)<P2006_1>

    明明的随机数 (random.pas/c/cpp) [问题描述] 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中 ...

  5. PPT页面动画制作

    因为武汉新型冠状肺炎的影响,今年自从2月3号开工以来,就在家办公.我的任务刚好是安排做PPT,虽说之前做过PPT,但大家都知道,作为一个IT测试工程师,更多的是测试工作,只有在培训,还有年终汇报的时候 ...

  6. Java基础 -5.3

    方法的递归调用 指的是一个方法自己调用自己的情况,利用递归调用可以解决一些重复且麻烦的问题 在进行我们递归调用的时候一般要考虑如下几点问题 一定要设置方法递归调用的结束条件 每一次调用的过程之中一定要 ...

  7. Spark入门:第4节 Spark程序:1 - 9

    五. Spark角色介绍 Spark是基于内存计算的大数据并行计算框架.因为其基于内存计算,比Hadoop中MapReduce计算框架具有更高的实时性,同时保证了高效容错性和可伸缩性.从2009年诞生 ...

  8. Dam-list

    1. Dam 2. 溃坝 3. 水坝对环境的影响 4. 水坝列表 4.1 黄河干流水电站列表 4.2 长江干流水电站列表 4.3 长江水系支流 431. 大渡河 432. 乌江 433. 雅砻江 43 ...

  9. Systemverilog for design 笔记(六)

    转载请标明出处 第一章 有限状态机建模(FSM,finite state machine) 1.1.    使用枚举类型建立状态机模型 l  三过程块建模风格:三个过程块分别实现: a.状态转换(al ...

  10. JS中,跨域调用(本地)另一个项目的方法

    IP地址,因为是本地的项目,所以我一开始写的是127.0.0.1...,但不对.应该写本机的IP地址才对!