在我们的Springboot MVC项目中,我们需要获取上下文路径。如果我们使用嵌入式tomcat,则以下代码可以正常工作。否则,如果将war文件部署到jboss服务器,则上下文路径返回null。
我试图将上下文根属性添加到jboss-web.xml中,但未进行任何更改。我还尝试将“ server.servlet.contextPath”属性添加到application.properties文件中,但是它不起作用。
春季启动版本:2.2.0.RELEASE
代码:
@Configuration
public class EurekaClientConfigBeanListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
String pathValue = System.getProperty("server.servlet.contextPath");
}