Refactor the Actuator MVC configuration to allow more customization
There is a new spring.factories entry for org.springframework.boot.actuate.autoconfigure.EndpointWebMvcConfiguration which loads extra beans into the MVC config for the Actuator. If the management context is a child context all the beans go in the child (except the Spring Security filter still). A big bonus is that you can add WebConfigurerAdapters to configure static resources etc. A new component called ManagementContextResolver can be used to locate the ApplicationContext for the MVC endpoints. Fixes gh-3345
This commit is contained in:
@@ -150,6 +150,23 @@ For example, the following will disable _all_ endpoints except for `info`:
|
||||
endpoints.info.enabled=true
|
||||
----
|
||||
|
||||
[[production-ready-customizing-endpoints-programmatically]]
|
||||
=== Adding Custom Endpoints
|
||||
|
||||
If you add a `@Bean` of type `Endpoint` then it will automatically be
|
||||
exposed over JMX and HTTP (if there is an server available). An HTTP
|
||||
endpoints can be customized further by creating a bean of type
|
||||
`MvcEndpoint`. Your `MvcEndpoint` is not a `@Controller` but it can use
|
||||
`@RequestMapping` (and `@Managed*`) to expose resources.
|
||||
|
||||
TIP: If you are doing this as a library feature consider adding a
|
||||
configuration class to `/META-INF/spring.factories` under the key
|
||||
`org.springframework.boot.actuate.autoconfigure.EndpointWebMvcConfiguration`.
|
||||
If you do that then the endpoint will move to a child context with all
|
||||
the other MVC endpoints if your users ask for a separate management port
|
||||
or address. A configuration declared this way can be a `WebConfigurerAdapter`
|
||||
if it wants to add static resources (for instance) to the management
|
||||
endpoints.
|
||||
|
||||
|
||||
[[production-ready-health]]
|
||||
@@ -1284,7 +1301,8 @@ described below.
|
||||
|
||||
[[production-ready-process-monitoring-configuration]]
|
||||
=== Extend configuration
|
||||
In `META-INF/spring.factories` file you have to activate the listener(s):
|
||||
In `META-INF/spring.factories` file you can activate the listener(s) that
|
||||
writes a PID file. Example:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
|
||||
@@ -1175,6 +1175,13 @@ Spring decides not to handle it. Most of the time this will not happen (unless y
|
||||
the default MVC configuration) because Spring will always be able to handle requests
|
||||
through the `DispatcherServlet`.
|
||||
|
||||
You can customize the static resource locations using
|
||||
`spring.resources.staticLocations` (replacing the default values with
|
||||
a list of directory locations). If you do this the default welcome
|
||||
page detection will switch to your custom locations, so if there is an
|
||||
`index.html` in any of your locations on startup, it will be the home
|
||||
page of the application.
|
||||
|
||||
In addition to the '`standard`' static resource locations above, a special case is made
|
||||
for http://www.webjars.org/[Webjars content]. Any resources with a path in `+/webjars/**+`
|
||||
will be served from jar files if they are packaged in the Webjars format.
|
||||
|
||||
Reference in New Issue
Block a user