Failed to load class “org.slf4j.impl.StaticLoggerBinder“.解决

下载的是Shiro,跟我学Shiro,运行时出现的问题

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

官网的解释是:

找不到SLF4J提供程序。
当在类路径上找不到SLF4J提供程序时,将报告此警告(即不是错误)消息。将slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar, slf4j-jdk14.jar或logback-classic.jar中的一个(仅一个)放置在类路径上即可解决此问题。请注意,这些提供程序必须针对slf4j-api 1.8或更高版本。

我们直接导入一个就好了,:记得reimport一下子

<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.7.25</version>
   <scope>compile</scope>
</dependency>

最后测试一下子

 @Test
    public void test() {
     

        DefaultSecurityManager securityManager = new DefaultSecurityManager();

        //设置authenticator
        ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
        authenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
        securityManager.setAuthenticator(authenticator);

        //设置authorizer
        ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();
        authorizer.setPermissionResolver(new WildcardPermissionResolver());
        securityManager.setAuthorizer(authorizer);

        //设置Realm
        DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro_test");
        ds.setUsername("root");
        ds.setPassword("root");

        JdbcRealm jdbcRealm = new JdbcRealm();
        jdbcRealm.setDataSource(ds);
        jdbcRealm.setPermissionsLookupEnabled(true);
        securityManager.setRealms(Arrays.asList((Realm) jdbcRealm));

        //将SecurityManager设置到SecurityUtils 方便全局使用
        SecurityUtils.setSecurityManager(securityManager);

        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken token = new UsernamePasswordToken("zhag", "123");
        subject.login(token);

        Assert.assertTrue(subject.isAuthenticated());


    }

Assert.assertTrue(subject.isAuthenticated());
它说的是期待是True,如果不是,就抛出异常

/**
	 * Asserts that a condition is true. If it isn't it throws
	 * an AssertionFailedError.
	 */
	static public void assertTrue(boolean condition) {
     
		assertTrue(null, condition);
	}

Failed to load class “org.slf4j.impl.StaticLoggerBinder“.解决_第1张图片

你可能感兴趣的:(Failed to load class “org.slf4j.impl.StaticLoggerBinder“.解决)