나는 shiro.ini와 봄을 가지고 달리는 시로를 얻을 수 있었지만 나는 시로 주석을 사용하고 싶었고 그래서 나는 ini 파일없이 시로 - 봄을 찾으려고했다. 하지만이게 나에게 힘든 시간을주고있다. 오류 :봄을 사용하는 Shiro는 "Shiro INI 구성이 없거나 비어 있거나 구성되지 않은 것으로 확인되었습니다."라고 알려줍니다.
org.apache.shiro.config.ConfigurationException : Shiro INI 구성이 없거나 비어 있거나 구성되지 않은 것으로 확인되었습니다. at org.apache.shiro.web.env.IniWebEnvironment.init (IniWebEnvironment.java:87) 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: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 (알 수없는 소스) 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 org.apache.tomcat.util.threads.InlineExecutorService.execute (InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit (알 수없는 소스) at org.apache.catalina.core.ContainerBase.startInternal (ContainerBase 된 .java : org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:183) 에서 org.apache.catalina.core.StandardEngine.startInternal (StandardEngine.java:262) 에서 953)에서 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) (알 수없는 소스) 태양에서 에서 . (알 수없는 소스)에서 org.apache.catalina.startup.Bootstrap.start (Bootstrap.java:355) at org.apache. catalina.startup.Bootstrap.main (Bootstrap.java:495)
Apr., 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();
}
}
웹 구성 :
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,
"/*");
}
}