You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Michael Chandler <Mi...@onassignment.com> on 2013/07/25 19:34:57 UTC

Shiro working, but JUnit is failing

I'm attempting to run some previously working integration tests via JUnit and I'm having difficulty doing so now that Shiro is implemented in my application.  It's very odd because the exception suggests that I'm missing dependencies, but I'm running this in Tomcat via Eclipse with Maven and the application runs well.  The unit tests fail as follows:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/Filter

This is how I've configured things in web.xml:
<filter>
                <filter-name>shiroFilter</filter-name>
                <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
                <init-param>
                                <param-name>targetFilterLifecycle</param-name>
                                <param-value>true</param-value>
                </init-param>
</filter>

<filter-mapping>
                <filter-name>shiroFilter</filter-name>
                <url-pattern>/*</url-pattern>
</filter-mapping>

My applicationContext.xml contains the following bean reference (I am omitting the securityManager, realms, etc.):
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
                <property name="securityManager" ref="securityManager" />
                <property name="loginUrl" value="/login" />
                <property name="successUrl" value="/users/welcome" />
                <property name="unauthorizedUrl" value="/unauthorized" />
</bean>

Nevertheless, I am getting that exception, but ONLY when using the JUnit test runner in Eclipse.  Does anyone know where I should start looking?

More complete stack trace below:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/Filter
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
                at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:746)
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:457)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                at com.oa.frontoffice.service.BeanService.<init>(BeanService.java:9)
                at com.oa.frontoffice.service.BeanService.getInstance(BeanService.java:17)
                at com.oa.frontoffice.gateway.HotListGateway.<init>(HotListGateway.java:22)
                at com.oa.frontoffice.gateway.TestHotListGatewayIntegration.setUp(TestHotListGatewayIntegration.java:24)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Mike


RE: Shiro working, but JUnit is failing

Posted by Michael Chandler <Mi...@onassignment.com>.
Disregard! :)  I'm not running my tests in Tomcat and am therefore missing dependencies that Tomcat provides.  This fixed my issue... completely unrelated to Shiro:

<dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <scope>test</scope>
</dependency>

From: Michael Chandler [mailto:Michael.Chandler@onassignment.com]
Sent: Thursday, July 25, 2013 10:35 AM
To: user@shiro.apache.org
Subject: Shiro working, but JUnit is failing

I'm attempting to run some previously working integration tests via JUnit and I'm having difficulty doing so now that Shiro is implemented in my application.  It's very odd because the exception suggests that I'm missing dependencies, but I'm running this in Tomcat via Eclipse with Maven and the application runs well.  The unit tests fail as follows:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/Filter

This is how I've configured things in web.xml:
<filter>
                <filter-name>shiroFilter</filter-name>
                <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
                <init-param>
                                <param-name>targetFilterLifecycle</param-name>
                                <param-value>true</param-value>
                </init-param>
</filter>

<filter-mapping>
                <filter-name>shiroFilter</filter-name>
                <url-pattern>/*</url-pattern>
</filter-mapping>

My applicationContext.xml contains the following bean reference (I am omitting the securityManager, realms, etc.):
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
                <property name="securityManager" ref="securityManager" />
                <property name="loginUrl" value="/login" />
                <property name="successUrl" value="/users/welcome" />
                <property name="unauthorizedUrl" value="/unauthorized" />
</bean>

Nevertheless, I am getting that exception, but ONLY when using the JUnit test runner in Eclipse.  Does anyone know where I should start looking?

More complete stack trace below:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/Filter
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
                at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:746)
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:457)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                at com.oa.frontoffice.service.BeanService.<init>(BeanService.java:9)
                at com.oa.frontoffice.service.BeanService.getInstance(BeanService.java:17)
                at com.oa.frontoffice.gateway.HotListGateway.<init>(HotListGateway.java:22)
                at com.oa.frontoffice.gateway.TestHotListGatewayIntegration.setUp(TestHotListGatewayIntegration.java:24)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:597)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
                at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
                at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Mike