【发布时间】:2017-02-21 15:21:39
【问题描述】:
我正在使用 NetBean 8.2 学习如何使用 Apache Shiro,但遇到了部署问题。当我尝试在 Glassfish 4.0 上调试 Web 应用程序时,我收到了这个错误:
Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.shiro.config.ConfigurationException: Shiro INI configuration was either not found or discovered to be empty/unconfigured.
错误信息与这篇文章中的完全相同:netbeans 8.0.1 cant find shiro.ini。但是,我的 Shiro.ini 已经在 WEB-INF 文件夹中(通过查看 WAR 文件确认)。
四郎伊尼
[main]
user.loginUrl = /login.xhtml
jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.authenticationQuery = select password from users where username = ?
jdbcRealm.userRolesQuery = select name from roles where userid = (select id from users where username = ?)
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.jdbcUrl=jdbc:mysql://<serverip>/<databasename>
ds.user = <username>
ds.password = <password>
jdbcRealm.dataSource = $ds
securityManager.realms = $jdbcRealm
[urls]
/login.xhtml = user
Web.xml
<listener>
<listener-class>
org.apache.shiro.web.env.EnvironmentLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
<init-param>
<param-name>configPath</param-name>
<param-value>classpath:shiro.INI</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
无论有没有 init-param 节点,控制台日志中都会显示相同的错误。
【问题讨论】:
-
WEB-INF 文件夹在哪里?
-
按照 Info-Q 和 BalusC 的教程,就在 WEB-INF 内部,而不是在 WEB-INF/lib 中。在我之前在 INI 中使用内置用户名的测试中,它将部署到 Glassfish。
-
应该在
WEB-INF/classes,因为您要求从classpath加载它。此外,如果不是 Windows,名称中的大小写也很重要,所以shiro.INI和shiro.ini指的是不同的资源 -
将其移至 WEB-INF/classes 也不行。我还更改了文件名和扩展名的大小写以匹配 Web.xml(使用 Windows)。很奇怪,它曾经部署过,但现在不会了。尝试重新启动机器和 Glassfish。初始测试没有 init-param 节点,我在根 web-inf 文件夹中有 ini 文件。
-
目前这个问题与 java-se 或 jsf-2.2 无关
标签: shiro