Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while creating spring MockHttpServletResponse, MissingResourceException even after adding javax.servet-api dependency

I am writing test for a servlet filter using spring MockHttpServletResponse and request. I am getting the following error while creating MockHttpServletResponse object.

Caused by: java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale en_US

I tried couple of things suggested on stackoverflow like adding javax.servlet-api to pom but even with that its not working. I tried adding tomcat server api in pom, but that is also not working.

My pom file just contains servlet api, jmockit and spring-test dependencies. And I dont have any message.properties or any other resource in classpath.

Is there any other dependency that I need to add here?

like image 365
user3565529 Avatar asked Feb 13 '26 02:02

user3565529


1 Answers

You need the appropriate version of javax.servlet:javax.servlet-api in the test classpath.

For Maven, you will need something similar to the following.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>test</scope>
</dependency>
like image 191
Sam Brannen Avatar answered Feb 15 '26 14:02

Sam Brannen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!