NutzCN Logo
问答 dubbo shiro集成异常 Unable to load optional path 'classpath:shiro.ini'.
发布于 1829天前 作者 Hamming 1549 次浏览 复制 上一个帖子 下一个帖子
标签:

配置文件如下

shiro.url.login=/login
shiro.url.unauth=/login/unauth
shiro.ini.urls:
/sys/** = authc
/monitor/** = authc
/tool/** = authc
/cms/** = authc
/wx/** = authc
/index = authc
/druid/** =authc
/swagger/** =authc
/login = anon
/static/** = anon
/open/** = anon

报错信息如下

[DEBUG] 14:36:15.387 org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:348) - Unable to load optional path 'classpath:shiro.ini'.
java.io.IOException: Resource [classpath:shiro.ini] could not be found.
	at org.apache.shiro.io.ResourceUtils.getInputStreamForPath(ResourceUtils.java:139)
	at org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:342)
	at org.apache.shiro.web.env.IniWebEnvironment.createIni(IniWebEnvironment.java:244)
	at org.apache.shiro.web.env.IniWebEnvironment.getDefaultIni(IniWebEnvironment.java:215)
	at org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:101)
	at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:69)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
	at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:313)
	at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:139)
	at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
	at org.nutz.boot.starter.shiro.NbShiroEnvironmentLoaderListener.contextInitialized(NbShiroEnvironmentLoaderListener.java:40)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.lambda$contextInitialized$1(NbServletContextListener.java:119)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.contextInitialized(NbServletContextListener.java:114)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:929)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:554)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:888)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:357)
	at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1443)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1407)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:821)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:276)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
	at org.eclipse.jetty.server.Server.start(Server.java:407)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:110)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:106)
	at org.eclipse.jetty.server.Server.doStart(Server.java:371)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.nutz.boot.starter.jetty.JettyStarter.start(JettyStarter.java:160)
	at org.nutz.boot.AppContext.startServers(AppContext.java:310)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at io.nutz.demo.dubbo.rpc.DubboRpcTimeClientLauncher.main(DubboRpcTimeClientLauncher.java:27)
[ERROR] 14:36:15.390 org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:152) - Shiro environment initialization failed
org.apache.shiro.config.ConfigurationException: Shiro INI configuration was either not found or discovered to be empty/unconfigured.
	at org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:110)
	at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:69)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
	at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:313)
	at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:139)
	at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
	at org.nutz.boot.starter.shiro.NbShiroEnvironmentLoaderListener.contextInitialized(NbShiroEnvironmentLoaderListener.java:40)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.lambda$contextInitialized$1(NbServletContextListener.java:119)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.contextInitialized(NbServletContextListener.java:114)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:929)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:554)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:888)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:357)
	at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1443)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1407)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:821)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:276)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
	at org.eclipse.jetty.server.Server.start(Server.java:407)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:110)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:106)
	at org.eclipse.jetty.server.Server.doStart(Server.java:371)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.nutz.boot.starter.jetty.JettyStarter.start(JettyStarter.java:160)
	at org.nutz.boot.AppContext.startServers(AppContext.java:310)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at io.nutz.demo.dubbo.rpc.DubboRpcTimeClientLauncher.main(DubboRpcTimeClientLauncher.java:27)
[WARN ] 14:36:15.390 org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:533) - Failed startup of context o.e.j.w.WebAppContext@288214b1{/,[file:///Users/apple/IdeaProjects/nutzboot/nutzboot-demo/nutzboot-demo-dubbo/nutzboot-demo-dubbo-rpc-client/target/classes/static/, jar:file:/Users/apple/.m2/repository/org/nutz/nutzboot-starter-swagger/2.3.9-SNAPSHOT/nutzboot-starter-swagger-2.3.9-20191101.064539-6.jar!/static/],UNAVAILABLE}
org.apache.shiro.config.ConfigurationException: Shiro INI configuration was either not found or discovered to be empty/unconfigured.
	at org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:110)
	at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:69)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)
	at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:313)
	at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:139)
	at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58)
	at org.nutz.boot.starter.shiro.NbShiroEnvironmentLoaderListener.contextInitialized(NbShiroEnvironmentLoaderListener.java:40)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.lambda$contextInitialized$1(NbServletContextListener.java:119)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.nutz.boot.starter.servlet3.NbServletContextListener.contextInitialized(NbServletContextListener.java:114)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:929)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:554)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:888)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:357)
	at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1443)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1407)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:821)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:276)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:524)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
	at org.eclipse.jetty.server.Server.start(Server.java:407)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:110)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:106)
	at org.eclipse.jetty.server.Server.doStart(Server.java:371)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.nutz.boot.starter.jetty.JettyStarter.start(JettyStarter.java:160)
	at org.nutz.boot.AppContext.startServers(AppContext.java:310)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at io.nutz.demo.dubbo.rpc.DubboRpcTimeClientLauncher.main(DubboRpcTimeClientLauncher.java:27)
[ERROR] 14:36:15.393 org.nutz.boot.NbApp.execute(NbApp.java:224) - something happen!!
java.io.IOException: Failed to bind to /0.0.0.0:8080
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:346)
	at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:307)
	at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
	at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:231)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.eclipse.jetty.server.Server.doStart(Server.java:385)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:72)
	at org.nutz.boot.starter.jetty.JettyStarter.start(JettyStarter.java:160)
	at org.nutz.boot.AppContext.startServers(AppContext.java:310)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:182)
	at io.nutz.demo.dubbo.rpc.DubboRpcTimeClientLauncher.main(DubboRpcTimeClientLauncher.java:27)
Caused by: java.net.BindException: Address already in use
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:342)
	... 11 more

不知道为什么 求大神解答

10 回复

放错目录了吧, resources目录下

木有 完整配置如下

server.port=8080
server.host=0.0.0.0

##shiro
shiro.realm.cache.enable =true
shiro.objects=shiroRealm

#shiro.ini.path=shiro.ini

shiro.url.login=/login
shiro.url.unauth=/login/unauth
shiro.ini.urls:
/sys/** = authc
/monitor/** = authc
/tool/** = authc
/cms/** = authc
/wx/** = authc
/index = authc
/druid/** =authc
/swagger/** =authc
/login = anon
/static/** = anon
/open/** = anon


dubbo.application.name=dubbo-rpc-client
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.application.qos.enable=false

有shiro.ini才会走这个分支的, 或者指定用ini

呃 没有的 全局 搜文件 找到一个

package io.nutz.nutzsite.common.qiniu;


import com.qiniu.util.Auth;

/**
 * @author haiming
 */
public final class QiniuConfig {
    //dummy ak & sk
    public static final String dummyAccessKey = "";
    public static final String dummySecretKey = "";
    public static final Auth dummyAuth = Auth.create(dummyAccessKey, dummySecretKey);

    public static final String dummyBucket = "";
    public static final String dummyKey = "";
    public static final String dummyDomain = "";
    public static final String dummyUrl= "";
    public static final String dummyUptoken = "";
    public static final String dummyInvalidUptoken = "";


    //code
    public static final int ERROR_CODE_BUCKET_NOT_EXIST = 631;
    public static final int ERROR_CODE_KEY_NOT_EXIST = 612;


    private QiniuConfig() {
    }

    public static boolean isTravis() {
        return "travis".equals(System.getenv("QINIU_TEST_ENV"));
    }
}

自定义MyActionChainMaker 未启用shiro 还是会报异常

package io.nutz.demo.dubbo.rpc;

import io.nutz.nutzsite.common.mvc.MyActionChainMaker;
import org.nutz.boot.NbApp;
import org.nutz.conf.NutConf;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.ChainBy;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Ok;

import com.alibaba.dubbo.config.annotation.Reference;

import io.nutz.demo.dubbo.rpc.service.TimeService;

@IocBean(create = "init", depose = "depose")
@IocBy(args="*slog")
@ChainBy(type= MyActionChainMaker.class, args={})
public class DubboRpcTimeClientLauncher {
	
	@Inject
	@Reference
	protected TimeService timeService;
    
    @Ok("raw")
    @At("/time/now")
    public long now() {
        return timeService.now();
    }

    /**
     * 启动方法
     * @param args
     */
    public static void main(String[] args) {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
        NutConf.USE_FASTCLASS = true;
    }

    /**
     * NB自身初始化完成后会调用这个方法
     */
    public void init() {

    }
    /**
     * 清空定时任务 否则会存在僵尸java进程
     */
    public void depose() {

    }
}

package io.nutz.nutzsite.common.mvc;

import io.nutz.nutzsite.common.mvc.processor.ErrorProcessor;
import io.nutz.nutzsite.common.mvc.processor.GlobalsSettingProcessor;
import io.nutz.nutzsite.common.mvc.processor.XssSqlFilterProcessor;
import org.nutz.integration.shiro.NutShiroProcessor;
import org.nutz.mvc.*;
import org.nutz.mvc.impl.NutActionChain;
import org.nutz.mvc.impl.processor.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 动作链 配置
 * https://nutzam.com/core/mvc/action_chain.html
 * @Author: Haimming
 * @Date: 2019-10-09 11:41
 * @Version 1.0
 */
public class MyActionChainMaker implements ActionChainMaker {

    /**
     * 该接口只有一个方法
     * @param config
     * @param ai
     * @return
     */
    @Override
    public ActionChain eval(NutConfig config, ActionInfo ai) {
        // 提醒: config可以获取ioc等信息, ai可以获取方法上的各种配置及方法本身
        // 正常处理的列表
        List<Processor> list = new ArrayList<>();
        // 设置base/msg等内置属性
        list.add(new UpdateRequestAttributesProcessor());

        list.add(new GlobalsSettingProcessor());
        // 设置编码信息@Encoding
        list.add(new EncodingProcessor());
        // 获取入口类的对象,从ioc或直接new
        list.add(new ModuleProcessor());
        //shiro
//        list.add(new NutShiroProcessor());
        // SQL 注入过滤 XSS过滤
        list.add(new XssSqlFilterProcessor());
        // 处理@Filters
        list.add(new ActionFiltersProcessor());
        // 处理@Adaptor
        list.add(new AdaptorProcessor());
        //必填项做判断
//        list.add(new ValidationProcessor());
        // 执行入口方法
        list.add(new MethodInvokeProcessor());
        // 对入口方法进行渲染@Ok
        list.add(new ViewProcessor());
        for (Processor p : list) {
            try {
                p.init(config, ai);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }

        // 最后是专门负责兜底的异常处理器,这个处理器可以认为是全局异常处理器,对应@Fail
        ErrorProcessor error = new ErrorProcessor();
        try {
            error.init(config, ai);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return new NutActionChain(list, error, ai);
    }
}

为什么会启动shiro 如何禁用呢

一直报错不知道哪里启动的shiro

[DEBUG] 16:05:56.762 org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:162) -     No conversion required, value is already a java.net.URL[]
[DEBUG] 16:05:56.777 org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:95) - Checking any specified config locations.
[DEBUG] 16:05:56.778 org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:100) - No INI instance or config locations specified.  Trying default config locations.
[DEBUG] 16:05:56.780 org.apache.shiro.io.ResourceUtils.loadFromClassPath(ResourceUtils.java:159) - Opening resource from class path [shiro.ini]
[DEBUG] 16:05:56.780 org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:348) - Unable to load optional path 'classpath:shiro.ini'.
java.io.IOException: Resource [classpath:shiro.ini] could not be found.
	at org.apache.shiro.io.ResourceUtils.getInputStreamForPath(ResourceUtils.java:139)
	at org.apache.shiro.web.env.IniWebEnvironment.convertPathToIni(IniWebEnvironment.java:342)
	at org.apache.shiro.web.env.IniWebEnvironment.createIni(IniWebEnvironment.java:244)
	at org.apache.shiro.web.env.IniWebEnvironment.getDefaultIni(IniWebEnvironment.java:215)
	at org.apache.shiro.web.env.IniWebEnvironment.parseConfig(IniWebEnvironment.java:101)
	at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:69)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45)
	at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40)

NbShiroEnvironmentLoaderListener

那 如何设置 不调用呢

nutzboot:run 正常不?

不正常 移除了shiro 现在重新试

添加回复
请先登陆
回到顶部