我使用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
<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节点,控制台日志中都会显示相同的错误。
答案 0 :(得分:0)
在web.xml中评论你的shiro代码并试试这个(我认为配置路径让事情变得更糟)
<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>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
首先初始化你的ds,然后才开始配置jdbcrealm,这样你就不会在正确初始化属性之前创建一些实例。
[main]
user.loginUrl = /login.xhtml
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.jdbcUrl=jdbc:mysql://<serverip>/<databasename>
ds.user = <username>
ds.password = <password>
jdbcRealm.dataSource = $ds
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 = ?)
securityManager.realms = $jdbcRealm
[urls]
/login.xhtml = user