Java 不带SpringBoot的Spring Boot执行器2.1.6的XML配置

Java 不带SpringBoot的Spring Boot执行器2.1.6的XML配置,java,spring,spring-boot,Java,Spring,Spring Boot,我正在尝试设置一个Spring项目,并希望使用Spring Boot Actuator 2.1.6。我已经找到了纯POJO配置的列表,但我的应用程序正在使用XML配置,并希望继续使用XML 我试过使用下面列出的配置,但它不起作用,因为它基于比我使用的更早版本的致动器 <bean name="endpointHandlerAdapter" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter"

我正在尝试设置一个Spring项目,并希望使用Spring Boot Actuator 2.1.6。我已经找到了纯POJO配置的列表,但我的应用程序正在使用XML配置,并希望继续使用XML

我试过使用下面列出的配置,但它不起作用,因为它基于比我使用的更早版本的致动器

<bean name="endpointHandlerAdapter" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapter" />
<bean name="endpointHandlerMapping" class="org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping" />
<bean class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$InfoPropertiesConfiguration" />
<bean name="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />

<beans>
    <context:annotation-config />
    <bean name="endpointAutoConfiguration" class="org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration"/>
</beans>

由于mvc包在较新版本的Spring boot中似乎不存在,因此使用该配置,我得到了许多未找到的类错误


编辑:阅读多一点,似乎所有可用的配置都是针对旧的Spring Boot Actuator 1,而不是新的东西。看起来所需的配置量成倍增加。仍然对答案感兴趣,但不抱希望。

这就是我们为spring+jersey项目所做的。由于我们使用的是较旧版本的spring(4.x),因此使用了spring boot actuator v1.5.22.0版本。排除了自动配置依赖项

pom.xml代码段:

<dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
        <version>1.5.22.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

org.springframework.boot
弹簧靴执行器
1.5.22.发布
org.springframework.boot
弹簧靴自动配置
XML配置代码段:

    <!-- Health -->
    <bean id="orderedHealthAggregator" class="org.springframework.boot.actuate.health.OrderedHealthAggregator" />
    <bean id="applicationHealthIndicator" class="org.springframework.boot.actuate.health.ApplicationHealthIndicator" />
    <bean id="dataSourceHealthIndicator" class="org.springframework.boot.actuate.health.DataSourceHealthIndicator">
        <constructor-arg index="0" ref="optimaxDataSource" />
    </bean>
    <bean id="jmsHealthIndicator" class="org.springframework.boot.actuate.health.JmsHealthIndicator">
        <constructor-arg index="0" ref="connectionFactory" />
    </bean>
    <bean id="mailHealthIndicator" class="org.springframework.boot.actuate.health.MailHealthIndicator">
        <constructor-arg index="0" ref="mailSender" />
    </bean>
    <!-- TODO: Set threshold value for disk space -->
    <bean id="diskSpaceHealthIndicatorProperties" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties" />
    <bean id="diskSpaceHealthIndicator" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicator">
        <constructor-arg index="0" ref="diskSpaceHealthIndicatorProperties" />
    </bean>
    <bean id="healthEndpoint" class="org.springframework.boot.actuate.endpoint.HealthEndpoint">
        <constructor-arg index="0" ref="orderedHealthAggregator" />
        <constructor-arg index="1" type="java.util.Map">
            <map>
                <entry key="application" value-ref="applicationHealthIndicator" />
                <entry key="db" value-ref="dataSourceHealthIndicator" />
                <entry key="jms" value-ref="jmsHealthIndicator" />
                <entry key="mail" value-ref="mailHealthIndicator" />
                <entry key="disk" value-ref="diskSpaceHealthIndicator" />
            </map>
        </constructor-arg>
    </bean>
    <!-- Git & Build Info -->
    <bean id="gitClasspathProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="singleton" value="true" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:git.properties</value>
            </list>
        </property>
    </bean>
    <bean id="gitProperties" class="org.springframework.boot.info.GitProperties">
        <constructor-arg index="0" ref="gitClasspathProperties" />
    </bean>
    <bean id="gitInfoContributor" class="org.springframework.boot.actuate.info.GitInfoContributor">
        <constructor-arg index="0" ref="gitProperties" />
        <constructor-arg index="1">
            <value type="org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode">FULL</value>
        </constructor-arg>
    </bean>
    <bean id="buildClasspathProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="singleton" value="true" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:build-info.properties</value>
            </list>
        </property>
    </bean>
    <bean id="buildProperties" class="org.springframework.boot.info.BuildProperties">
        <constructor-arg index="0" ref="buildClasspathProperties" />
    </bean>
    <bean id="buildInfoContributor" class="org.springframework.boot.actuate.info.BuildInfoContributor">
        <constructor-arg index="0" ref="buildProperties" />
    </bean>
    <bean id="infoEndpoint" class="org.springframework.boot.actuate.endpoint.InfoEndpoint">
        <constructor-arg index="0" type="java.util.List">
        <list>
            <ref bean="gitInfoContributor" />
            <ref bean="buildInfoContributor" />
        </list>
        </constructor-arg>
    </bean>
    <!-- Metrics -->
    <bean id="systemPublicMetrics" class="org.springframework.boot.actuate.endpoint.SystemPublicMetrics" />
    <bean id="metricsEndpoint" class="org.springframework.boot.actuate.endpoint.MetricsEndpoint">
        <constructor-arg index="0" ref="systemPublicMetrics" />
    </bean>
    <!-- Beans -->
    <bean id="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
    <!-- Env -->
    <bean id="environmentEndpoint" class="org.springframework.boot.actuate.endpoint.EnvironmentEndpoint" />
    <!-- Thread Dump -->
    <bean id="threadDumpEndpoint" class="org.springframework.boot.actuate.endpoint.DumpEndpoint" />

类路径:git.properties
满满的
类路径:build-info.properties
通过Jersey资源公开了监视功能

@Path("/actuator")
public class ActuatorResource {

    private static final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);

    @Autowired
    private HealthEndpoint healthEndpoint;

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    @Path("/health")
    @Transactional(readOnly = true)
    public Response getHealth() throws JsonProcessingException {
        return invoke(healthEndpoint);
    }
    
    private Response invoke(Endpoint<?> endpoint) {

        try {
            return Response.ok().entity(mapper.writeValueAsString(endpoint.invoke())).build();
        } catch (Throwable t) {
            logger.error("Error invoking endpoint : {}", endpoint.getClass().getName(), t);
            return Response.serverError().entity("Request processing failed").build();
        }
    }
}
```
路径(“/actuator”) 公共类ActuatorResource{ private static final ObjectMapper mapper=new ObjectMapper().enable(SerializationFeature.INDENT_输出); @自动连线 私人健康终点; @得到 @产生({MediaType.APPLICATION_JSON}) @路径(“/health”) @事务(只读=真) 公共响应getHealth()引发JsonProcessingException{ 返回调用(healthEndpoint); } 私有响应调用(端点){ 试一试{ 返回Response.ok().entity(mapper.writeValueAsString(endpoint.invoke()).build(); }捕获(可丢弃的t){ error(“调用端点:{},endpoint.getClass().getName(),t时出错); 返回Response.serverError().entity(“请求处理失败”).build(); } } } ```
这就是我们为spring+jersey项目所做的。由于我们使用的是较旧版本的spring(4.x),因此使用了spring boot actuator v1.5.22.0版本。排除了自动配置依赖项

pom.xml代码段:

<dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
        <version>1.5.22.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

org.springframework.boot
弹簧靴执行器
1.5.22.发布
org.springframework.boot
弹簧靴自动配置
XML配置代码段:

    <!-- Health -->
    <bean id="orderedHealthAggregator" class="org.springframework.boot.actuate.health.OrderedHealthAggregator" />
    <bean id="applicationHealthIndicator" class="org.springframework.boot.actuate.health.ApplicationHealthIndicator" />
    <bean id="dataSourceHealthIndicator" class="org.springframework.boot.actuate.health.DataSourceHealthIndicator">
        <constructor-arg index="0" ref="optimaxDataSource" />
    </bean>
    <bean id="jmsHealthIndicator" class="org.springframework.boot.actuate.health.JmsHealthIndicator">
        <constructor-arg index="0" ref="connectionFactory" />
    </bean>
    <bean id="mailHealthIndicator" class="org.springframework.boot.actuate.health.MailHealthIndicator">
        <constructor-arg index="0" ref="mailSender" />
    </bean>
    <!-- TODO: Set threshold value for disk space -->
    <bean id="diskSpaceHealthIndicatorProperties" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicatorProperties" />
    <bean id="diskSpaceHealthIndicator" class="org.springframework.boot.actuate.health.DiskSpaceHealthIndicator">
        <constructor-arg index="0" ref="diskSpaceHealthIndicatorProperties" />
    </bean>
    <bean id="healthEndpoint" class="org.springframework.boot.actuate.endpoint.HealthEndpoint">
        <constructor-arg index="0" ref="orderedHealthAggregator" />
        <constructor-arg index="1" type="java.util.Map">
            <map>
                <entry key="application" value-ref="applicationHealthIndicator" />
                <entry key="db" value-ref="dataSourceHealthIndicator" />
                <entry key="jms" value-ref="jmsHealthIndicator" />
                <entry key="mail" value-ref="mailHealthIndicator" />
                <entry key="disk" value-ref="diskSpaceHealthIndicator" />
            </map>
        </constructor-arg>
    </bean>
    <!-- Git & Build Info -->
    <bean id="gitClasspathProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="singleton" value="true" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:git.properties</value>
            </list>
        </property>
    </bean>
    <bean id="gitProperties" class="org.springframework.boot.info.GitProperties">
        <constructor-arg index="0" ref="gitClasspathProperties" />
    </bean>
    <bean id="gitInfoContributor" class="org.springframework.boot.actuate.info.GitInfoContributor">
        <constructor-arg index="0" ref="gitProperties" />
        <constructor-arg index="1">
            <value type="org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode">FULL</value>
        </constructor-arg>
    </bean>
    <bean id="buildClasspathProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="singleton" value="true" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:build-info.properties</value>
            </list>
        </property>
    </bean>
    <bean id="buildProperties" class="org.springframework.boot.info.BuildProperties">
        <constructor-arg index="0" ref="buildClasspathProperties" />
    </bean>
    <bean id="buildInfoContributor" class="org.springframework.boot.actuate.info.BuildInfoContributor">
        <constructor-arg index="0" ref="buildProperties" />
    </bean>
    <bean id="infoEndpoint" class="org.springframework.boot.actuate.endpoint.InfoEndpoint">
        <constructor-arg index="0" type="java.util.List">
        <list>
            <ref bean="gitInfoContributor" />
            <ref bean="buildInfoContributor" />
        </list>
        </constructor-arg>
    </bean>
    <!-- Metrics -->
    <bean id="systemPublicMetrics" class="org.springframework.boot.actuate.endpoint.SystemPublicMetrics" />
    <bean id="metricsEndpoint" class="org.springframework.boot.actuate.endpoint.MetricsEndpoint">
        <constructor-arg index="0" ref="systemPublicMetrics" />
    </bean>
    <!-- Beans -->
    <bean id="beansEndpoint" class="org.springframework.boot.actuate.endpoint.BeansEndpoint" />
    <!-- Env -->
    <bean id="environmentEndpoint" class="org.springframework.boot.actuate.endpoint.EnvironmentEndpoint" />
    <!-- Thread Dump -->
    <bean id="threadDumpEndpoint" class="org.springframework.boot.actuate.endpoint.DumpEndpoint" />

类路径:git.properties
满满的
类路径:build-info.properties
通过Jersey资源公开了监视功能

@Path("/actuator")
public class ActuatorResource {

    private static final ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);

    @Autowired
    private HealthEndpoint healthEndpoint;

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    @Path("/health")
    @Transactional(readOnly = true)
    public Response getHealth() throws JsonProcessingException {
        return invoke(healthEndpoint);
    }
    
    private Response invoke(Endpoint<?> endpoint) {

        try {
            return Response.ok().entity(mapper.writeValueAsString(endpoint.invoke())).build();
        } catch (Throwable t) {
            logger.error("Error invoking endpoint : {}", endpoint.getClass().getName(), t);
            return Response.serverError().entity("Request processing failed").build();
        }
    }
}
```
路径(“/actuator”) 公共类ActuatorResource{ private static final ObjectMapper mapper=new ObjectMapper().enable(SerializationFeature.INDENT_输出); @自动连线 私人健康终点; @得到 @产生({MediaType.APPLICATION_JSON}) @路径(“/health”) @事务(只读=真) 公共响应getHealth()引发JsonProcessingException{ 返回调用(healthEndpoint); } 私有响应调用(端点){ 试一试{ 返回Response.ok().entity(mapper.writeValueAsString(endpoint.invoke()).build(); }捕获(可丢弃的t){ error(“调用端点:{},endpoint.getClass().getName(),t时出错); 返回Response.serverError().entity(“请求处理失败”).build(); } } } ```
未找到哪些类?org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapterorg.springframework.boot.endpoint.actuate.EndpointHandlerMapping未找到哪些类?org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerAdapterorg.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping