shiro.iniとspringでshiroを走らせることができましたが、shiroの注釈を使いたいので、iniファイルなしでshiro-springに行きました。しかし、これは私に苦労しています エラー:Shiroがspringを使用すると、 "Shiro INI設定が見つからなかったか、空/未構成であることが判明しました。"
org.apache.shiro.config.ConfigurationException:Shiro INI設定が見つからなかったか、空/未構成であることが判明しました。 (IniWebEnvironment.java:87) at org.apache.shiro.weil.util.LifecycleUtils.init(LifecycleUtils.java:45) .LifecycleUtils.init(LifecycleUtils.java:40) at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:226) at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment EnvironmentLoader.java:138) at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4742) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5206) at org.apache.catalina.util .LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1439) at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase .java:1429) at java.util.concurrent.FutureTask.run(不明なソース) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent。 AbstractExecutorService.submit(Unknown Source) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:953) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872) at org .apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1439) at org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1429) at java.util.concurrent.FutureTask.run(不明なソース) atコンテナベースのコンテナベースのコンテナ。 .java:953) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache .catalina.core.StandardService.startInternal(StandardService.java:422) at org.apache.catalina.util.LifecycleBa se.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)日でsun.reflect.NativeMethodAccessorImpl.invokeでsun.reflect.NativeMethodAccessorImpl.invoke0(ネイティブメソッド) (不明なソース) でorg.apache.catalina.startup.Catalina.start(Catalina.java:655) で 。 (未知のソース) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355) at org.apache。 catalina.startup.Bootstrap.main(Bootstrap.java:495)
Apr 17、2017 4:15:32 PM org.apache.catalina.core。StandardContextでstartInternal
コード:春の設定:
package com.studentshare.config;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.Filter;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.realm.jdbc.JdbcRealm;
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.studentshare")
public class AppConfig {
@Bean
public JdbcRealm myRealm() {
JdbcRealm jdbcRealm = new JdbcRealm();
jdbcRealm.setAuthenticationQuery("select password from unishare.users where user_name = ?");
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("root");
dataSource.setDatabaseName("unishare");
jdbcRealm.setDataSource(dataSource);
jdbcRealm.setCredentialsMatcher(new HashedCredentialsMatcher());
return jdbcRealm;
}
@Bean
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
return new LifecycleBeanPostProcessor();
}
@Bean
public DefaultWebSecurityManager securityManager(@Autowired JdbcRealm myRealm) {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(myRealm);
return securityManager;
}
@Bean
public BasicHttpAuthenticationFilter myAuthBasic(){
return new BasicHttpAuthenticationFilter();
}
@Bean
public ShiroFilterFactoryBean ShiroFilter(@Autowired DefaultWebSecurityManager securityManager,@Autowired BasicHttpAuthenticationFilter myAuthBasic) {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
Map<String, Filter> filters = new HashMap<>();
filters.put("myAuthcBasic", myAuthBasic);
shiroFilter.setFilters(filters);
/*Map<String, String> filterChainDefinitionMap = new HashMap<>();
filterChainDefinitionMap.put("/", "authcBasic");*/
shiroFilter.setFilterChainDefinitions("/ = myAuthcBasic");//p(filterChainDefinitionMap);
return shiroFilter;
}
@DependsOn("lifecycleBeanPostProcessor")
@Bean
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
return new DefaultAdvisorAutoProxyCreator();
}
}
Web構成:
package com.studentshare.config;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.shiro.web.env.EnvironmentLoaderListener;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
@Override
protected Class[] getServletConfigClasses() {
return null;
}
@Override
protected Filter[] getServletFilters() {
return new Filter[] { new ShiroFilter() };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.addListener(EnvironmentLoaderListener.class);
EnumSet<DispatcherType> shiroDispatchers = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
DispatcherType.INCLUDE, DispatcherType.ERROR);
FilterRegistration shiroFilter = servletContext.addFilter("ShiroFilter", DelegatingFilterProxy.class);
shiroFilter.setInitParameter("targetFilterLifecycle", "true");
shiroFilter.addMappingForUrlPatterns(shiroDispatchers, false,
"/*");
}
}