You encounter the following error for a spring boot application that is packaged as a war file when deployed to Tanzu Application Service for VMs (TAS for VMs).
2021-12-15T06:20:36.809-07:00 [APP/PROC/WEB/0] [OUT] 2021-12-15 13:20:36.808 ERROR 30 --- [ main] o.a.c.w.AbstractFileResourceSet : Resource for web application [/sfcalculators] at path [/WEB-INF/lib/client_certificate_mapper-1.11.0_RELEASE.jar] was not loaded as the canonical path [/.java-buildpack/client_certificate_mapper/client_certificate_mapper-1.11.0_RELEASE.jar] did not match. Use of symlinks is one possible cause.
The issue is a result of the Java Buildpack adding jars to /app/WEB-INF/lib directory as symlinks namely.
a. client_certificate_mapper-1.11.0_RELEASE.jar
b. spring_auto_reconfiguration-2.12.0_RELEASE.jar
c. container_customizer-2.6.0_RELEASE.jar
To resolve this issue, apply the steps listed Option 1 or Option 2.
Option 1
Package the app as a jar file instead of a war file.
For example, for a maven project pom.xml, add the following:
<packaging>jar</packaging>
Option 2
Set Tomcat context resource allowLinking to true.
Configure tomcat programmatically.
**TomcatConfiguration.java
package mypackage;
import org.apache.catalina.webresources.StandardRoot;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.apache.catalina.Context;
@Configuration
public class TomcatConfiguration {
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() {
return (TomcatServletWebServerFactory container) -> {
container.addContextCustomizers((Context context) -> {
// This configuration is used to allow symlink on resources
StandardRoot sr = new StandardRoot();
sr.setAllowLinking(true);
context.setResources(sr);
});
};
}
}
The code above is equivalent to adding the resource to conf/context.xml.
** context.xml
<?xml version="1.0"?>
<Context>
<Resources allowLinking="true" />
</Context>
For more information, on configuring Tomcat, refer to Apache Tomcat 9 Configuration Reference.
Note: Option 2 works for Spring Boot v2.x and Tomcat v9.0.x.