From 6443800038665209ab0760497118f0f902408d25 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 9 Dec 2013 16:17:53 +0000 Subject: [PATCH] Add actuator-noweb sample --- .../EndpointAutoConfiguration.java | 3 - spring-boot-samples/pom.xml | 1 + .../spring-boot-sample-actuator-noweb/pom.xml | 34 ++++++++++ .../sample/actuator/HelloWorldService.java | 32 +++++++++ .../SampleActuatorNoWebApplication.java | 35 ++++++++++ .../sample/actuator/ServiceProperties.java | 36 ++++++++++ .../src/main/resources/application.properties | 5 ++ .../SampleActuatorNoWebApplicationTests.java | 68 +++++++++++++++++++ 8 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/HelloWorldService.java create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/ServiceProperties.java create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties create mode 100644 spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplicationTests.java diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java index 5cf1e88c7e..3033494544 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.java @@ -47,7 +47,6 @@ import org.springframework.boot.actuate.trace.TraceRepository; import org.springframework.boot.autoconfigure.AutoConfigurationReport; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.bind.PropertiesConfigurationFactory; @@ -57,7 +56,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; -import org.springframework.http.MediaType; /** * {@link EnableAutoConfiguration Auto-configuration} for common management @@ -68,7 +66,6 @@ import org.springframework.http.MediaType; * @author Greg Turnquist */ @Configuration -@ConditionalOnClass(MediaType.class) public class EndpointAutoConfiguration { @Autowired(required = false) diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 752fe1ab22..0ee8f5348c 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -16,6 +16,7 @@ spring-boot-sample-actuator spring-boot-sample-actuator-log4j + spring-boot-sample-actuator-noweb spring-boot-sample-actuator-ui spring-boot-sample-amqp spring-boot-sample-aop diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml new file mode 100644 index 0000000000..de4eef79d0 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 0.5.0.BUILD-SNAPSHOT + + spring-boot-sample-actuator-noweb + jar + + ${basedir}/../.. + + + + ${project.groupId} + spring-boot-starter-actuator + + + ${project.groupId} + spring-boot-starter-shell-remote + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/HelloWorldService.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/HelloWorldService.java new file mode 100644 index 0000000000..baea40d432 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/HelloWorldService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.sample.actuator; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class HelloWorldService { + + @Autowired + private ServiceProperties configuration; + + public String getHelloMessage() { + return "Hello " + this.configuration.getName(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplication.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplication.java new file mode 100644 index 0000000000..eee9972708 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.sample.actuator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@EnableConfigurationProperties +@ComponentScan +public class SampleActuatorNoWebApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleActuatorNoWebApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/ServiceProperties.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/ServiceProperties.java new file mode 100644 index 0000000000..5b111e166e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/java/org/springframework/boot/sample/actuator/ServiceProperties.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.sample.actuator; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@ConfigurationProperties(name = "service", ignoreUnknownFields = false) +@Component +public class ServiceProperties { + + private String name = "World"; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties new file mode 100644 index 0000000000..3df2e92ef3 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/main/resources/application.properties @@ -0,0 +1,5 @@ +service.name: Phil +shell.ssh.enabled: true +shell.ssh.port: 2222 +shell.auth: simple +shell.auth.simple.user.password: password diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplicationTests.java new file mode 100644 index 0000000000..8711f8a456 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/org/springframework/boot/sample/actuator/SampleActuatorNoWebApplicationTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.sample.actuator; + +import static org.junit.Assert.assertNotNull; + +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.actuate.endpoint.MetricsEndpoint; +import org.springframework.context.ConfigurableApplicationContext; + +/** + * Basic integration tests for service demo application. + * + * @author Dave Syer + */ +public class SampleActuatorNoWebApplicationTests { + + private static ConfigurableApplicationContext context; + + @BeforeClass + public static void start() throws Exception { + Future future = Executors + .newSingleThreadExecutor().submit( + new Callable() { + @Override + public ConfigurableApplicationContext call() throws Exception { + return SpringApplication + .run(SampleActuatorNoWebApplication.class); + } + }); + context = future.get(60, TimeUnit.SECONDS); + } + + @AfterClass + public static void stop() { + if (context != null) { + context.close(); + } + } + + @Test + public void endpointsExist() throws Exception { + assertNotNull(context.getBean(MetricsEndpoint.class)); + } + +}