使用 spring-boot-actuator 是否会更改 spring 应用程序的上下文根? [英] Does having spring-boot-actuator changes the context root of the spring application?
问题描述
根据这篇文章,通过pom.xml
中的 spring-boot-actuator
依赖项,我可以从 actuator
端点中受益.但是,我观察到它破坏了我现有的 spring 应用程序(它不是 spring-boot 应用程序).
According to this post, by having the spring-boot-actuator
dependency in pom.xml
, I could benefits from the actuator
endpoints. However, I observed it breaks my existing my spring application (It is not a spring-boot application).
我在 pom.xml 中的依赖项中添加了以下内容
I added the following to my dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
就是这样.我还没有对应用程序进行任何更改.我使用 maven-t7-plugin
启动了容器.现在我的应用程序端点 http://localhost:8010/mycontext/foo
返回 404.我在 pom.xml
中注释掉了上面的 dependency
.现在我的应用程序为上述请求返回 200 OK
.
Thats it. I did not make any changes to application yet.
I started the container using maven-t7-plugin
.
Now my application endpoint http://localhost:8010/mycontext/foo
is returning 404. I commented out the above dependency
in pom.xml
.
Now my application returns 200 OK
for the above request.
请帮助我解决问题.我找不到任何明显的原因.
Kindly help troubleshoot me as what is going wrong. I could not find any obvious reasons.
谢谢
推荐答案
当我在控制台查看 spring 日志时,我注意到以下内容:WARN org.springframework.web.servlet.PageNotFound - 在 DispatcherServlet 中未找到具有 URI [/mycontext/foo] 的 HTTP 请求的映射,名称为DispatcherServlet"
.
When I looked at the spring logs in console, I noticed the following:
WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/mycontext/foo] in DispatcherServlet with name 'DispatcherServlet'
.
由于我在 Spring 应用程序中配置了 DispatcherServlet
,所以我不能使用 spring-boot-actuator
的 auto-configure
.
Since I have configured DispatcherServlet
in my Spring application, I cannot use auto-configure
of spring-boot-actuator
.
一旦我排除了 dependency
,我的应用程序就会按预期工作.
Once I excluded that dependency
, my application works as expected.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>1.2.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于使用 spring-boot-actuator 是否会更改 spring 应用程序的上下文根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!