No bean named 'shiroFilter' available when convert from xml to JavaConfig.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

No bean named 'shiroFilter' available when convert from xml to JavaConfig.

iGem
This post was updated on .
I've been successfully integrated shiro into my spring application and it has been running accordingly for the passed 2 yrs. The configuration was in xml file(defined in application-context.xml) I'm saying this to state that my configuration using xml file is working accordingly.

my system is tomcat 8 + spring mvc 4.3.10 + hibernate 5.2.10.Final + shiro 1.4.0

Now I'm trying to convert the xml file into java config (defined all beans in a class.. trying to NOT use xml file anymore), and I'm facing spring unable to find shiroFilter bean, in which I've defined in my java class.

        @Bean(name="shiroFilter")
        public ShiroFilterFactoryBean shiroFilter(){
                ShiroFilterFactoryBean sffb = new ShiroFilterFactoryBean();
                sffb.setSecurityManager(securityManager());
                sffb.setLoginUrl("/login.jsp");
                sffb.setUnauthorizedUrl("/unauthorized.jsp");
                               
                Map<String, String> chains = new HashMap<String, String>();
                chains.put("/userProfile/**", "anon");
                chains.put("/resources/**", "anon");
                chains.put("/**", "ssl, authc");
                sffb.setFilterChainDefinitionMap(chains);
                return sffb;
        }

Been searching hints over the web but nothing helps to resolve this problem. If I leave the configuration in application-context.xml the system works flawlessly. However when I convert it to Java Config I got the following errors on console when server starts up.

error log:
----------
[2017-07-21 14:43:39] [INFO ] [] org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1121 ms
Jul 21, 2017 2:43:39 PM org.apache.tomcat.util.descriptor.web.SecurityConstraint findUncoveredHttpMethods
SEVERE: For security constraints with URL pattern [/prms/*] only the HTTP methods [POST GET] are covered. All other methods are uncovered.
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.filter.DelegatingFilterProxy - Initializing filter 'shiroFilter'
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Adding [servletConfigInitParams] PropertySource with lowest search precedence
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Adding [servletContextInitParams] PropertySource with lowest search precedence
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Adding [jndiProperties] PropertySource with lowest search precedence
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
[2017-07-21 14:43:39] [DEBUG] [] org.springframework.web.context.support.StandardServletEnvironment - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
Jul 21, 2017 2:43:39 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter shiroFilter
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'shiroFilter' available
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1207)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1084)
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235)
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:236)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4659)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5281)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

Any help would be appreciated.
Loading...