I have a spring Boot application api which is not recognized as a spring boot application in PCF. Also the context-path is defined other than the default one. I found some resources cloud foundry not recognizing the spring boot appand, tried adding the suggested configuration but still the app doesn't getting recognized as a spring boot. I reach to the root cause that the the routes which I have in api has the ui application routes too. And, which is correct in my case. However, when I remove those UI routes just to test out from api then PCF recognize the application as a spring boot app. api routes is following the naming convention by cloud foundry ui routes in api Does anybody has any idea about managing the multiple application routes in spring boot app (specifically ui routes) and still get recognized as a spring boot application?
I have a Spring Boot app that is deployed as a backend service. It shows up in apps manager, but there are no Spring Boot features (thread dumps, info endpoint, log level setting etc.).
Tried adding below configuration in the code. It worked for other microservice where it doesn't have the UI routes mapping in the application.
@Configuration(proxyBeanMethods = false)
public class CloudFoundryConfiguration {
private static final String CONTEXT_CLOUDFOUNDRY_APPLICATION = "/cloudfoundryapplication";
@Bean
public TomcatServletWebServerFactory servletWebServerFactory() {
return new TomcatServletWebServerFactory() {
@Override
protected void prepareContext(Host host,
ServletContextInitializer[] initializers) {
super.prepareContext(host, initializers);
StandardContext child = new StandardContext();
child.addLifecycleListener(new Tomcat.FixContextListener());
child.setPath(CONTEXT_CLOUDFOUNDRY_APPLICATION);
ServletContainerInitializer initializer = getServletContextInitializer(
getContextPath());
child.addServletContainerInitializer(initializer, Collections.emptySet());
child.setCrossContext(true);
host.addChild(child);
}
};
}
private ServletContainerInitializer getServletContextInitializer(String contextPath) {
return (classes, context) -> {
Servlet servlet = new GenericServlet() {
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
ServletContext context = req.getServletContext().getContext(contextPath);
context.getRequestDispatcher(CONTEXT_CLOUDFOUNDRY_APPLICATION).forward(req, res);
}
};
context.addServlet("cloudfoundry", servlet).addMapping("/*");
};
}