Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RepositoryRestResource resources started returning 404 errors after running for a while

I have a workaround for this problem, but I wanted to post this in case anybody else ran into this.

We have a Spring boot web application that is being packaged as a war file and deployed to Tomcat. It has several PagingAndSortingRepository classes annotated with @RepositoryRestResource that serve rest requests, and a few other classes annotated with @RestController. The RestController classes do make some calls to the repository classes.

Everything has been working fine through the 2.2.5.RELEASE version of spring-boot. We ran into a problem after upgrading to 2.2.6.RELEASE. Everything was fine (meaning both types of rest resources could be accessed) but after running for about 10-15 minutes, everything that was accessed through a RepositoryRestResource started returning 404 errors. No error messages in any logs, they just started returning 404 errors when they had been working fine previously. The RestControllers kept working fine the whole time. After reverting back to the 2.2.5.RELEASE, we had no more problems.

Since we are using dependencyManagement, I don't think it was a version mismatch issue. None of the spring artifacts in the pom.xml file have versions. Here is what is in the pom:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.2.5.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
like image 758
Leslie Miller Avatar asked Oct 15 '22 04:10

Leslie Miller


2 Answers

I have reproduced exactly the same issue after upgrading to spring-boot 2.2.6 : PagingAndSortingRepository classes annotated with @RepositoryRestResource started randomly to return 404 errors... Rollbacking to version 2.2.5 solved the problem !

like image 56
Yann Avatar answered Oct 19 '22 01:10

Yann


Here was our problem: it turns out we had multiple context.xml files and also multiple application.properties files, although it seemed the main culprit was the context.xml file. Something (Netbeans?) keeps generating src/main/webapp/META-INF/context.xml file, but in production we use an external one, not one that is bundled with the war file. Anyway, what happened is the context.xml file that was generated in src was getting bundled with the war file, and it had a different path than the production context file. I don't know why, but when using the 2.2.5 version it seemed to ignore that bogus bundled context.xml file, and with 2.2.6 it got confused and started returning the "not found" errors. Removing that extraneous context.xml file from the war file got it working.

Here is the generated (and bogus) context.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Context path=""/>

And here is the working app.xml file located under conf/Catalina/localhost:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/tdapp" docBase="${catalina.base}/warfiles/tdapp.war">
    <Environment name="spring.config.location" value="file:/usr/share/tdapp/application.properties" type="java.lang.String"/>
</Context>
like image 27
Leslie Miller Avatar answered Oct 19 '22 00:10

Leslie Miller