mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
[bs-19] Add samples and CLI support for Spring Integration
$ cd spring-bootstrap-cli $ export SPRING_HOME=target $ src/main/scripts/spring run samples/integration.groovy The big disadvantage at the moment is that there is no goo way to detect Spring Integration in the AST (at least not as good as @Enable*). So for now we are looking for @MessageEndpoint or a class name with SpringIntegration in it. [#48151147]
This commit is contained in:
parent
d82c50804f
commit
83e0ea22c1
15
spring-bootstrap-cli/samples/integration.groovy
Normal file
15
spring-bootstrap-cli/samples/integration.groovy
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package org.test
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class SpringIntegrationExample implements CommandLineRunner {
|
||||||
|
|
||||||
|
def builder = new IntegrationBuilder()
|
||||||
|
def flow = builder.messageFlow {
|
||||||
|
transform {"Hello, $it!"}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) {
|
||||||
|
print flow.sendAndReceive("World")
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package org.test
|
package org.test
|
||||||
|
|
||||||
@GrabResolver(name='spring-milestone', root='http://repo.springframework.org/milestone')
|
|
||||||
@Grab("org.hsqldb:hsqldb-j5:2.0.0")
|
@Grab("org.hsqldb:hsqldb-j5:2.0.0")
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableBatchProcessing
|
@EnableBatchProcessing
|
||||||
@ -33,6 +32,7 @@ class JobConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import groovy.util.logging.Log
|
||||||
import org.springframework.util.StringUtils
|
import org.springframework.util.StringUtils
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.test
|
package org.test
|
||||||
|
|
||||||
@GrabResolver(name='spring-snapshot', root='http://repo.springframework.org/snapshot')
|
|
||||||
@Grab("org.springframework.bootstrap:spring-bootstrap-service:0.0.1-SNAPSHOT")
|
@Grab("org.springframework.bootstrap:spring-bootstrap-service:0.0.1-SNAPSHOT")
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -33,6 +33,7 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer;
|
|||||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration;
|
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration;
|
||||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBootstrapCompilerAutoConfiguration;
|
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBootstrapCompilerAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration;
|
||||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration;
|
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +57,7 @@ public class GroovyCompiler {
|
|||||||
new SpringBootstrapCompilerAutoConfiguration(),
|
new SpringBootstrapCompilerAutoConfiguration(),
|
||||||
new SpringMvcCompilerAutoConfiguration(),
|
new SpringMvcCompilerAutoConfiguration(),
|
||||||
new SpringBatchCompilerAutoConfiguration(),
|
new SpringBatchCompilerAutoConfiguration(),
|
||||||
|
new SpringIntegrationCompilerAutoConfiguration(),
|
||||||
new SpringBootstrapCompilerAutoConfiguration() };
|
new SpringBootstrapCompilerAutoConfiguration() };
|
||||||
|
|
||||||
private GroovyCompilerConfiguration configuration;
|
private GroovyCompilerConfiguration configuration;
|
||||||
|
@ -16,8 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.bootstrap.cli.compiler.autoconfigure;
|
package org.springframework.bootstrap.cli.compiler.autoconfigure;
|
||||||
|
|
||||||
|
import groovy.grape.Grape;
|
||||||
import groovy.lang.GroovyClassLoader;
|
import groovy.lang.GroovyClassLoader;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.codehaus.groovy.ast.AnnotationNode;
|
import org.codehaus.groovy.ast.AnnotationNode;
|
||||||
import org.codehaus.groovy.ast.ClassNode;
|
import org.codehaus.groovy.ast.ClassNode;
|
||||||
import org.codehaus.groovy.classgen.GeneratorContext;
|
import org.codehaus.groovy.classgen.GeneratorContext;
|
||||||
@ -78,9 +82,21 @@ public class SpringBootstrapCompilerAutoConfiguration extends CompilerAutoConfig
|
|||||||
public void applyToMainClass(GroovyClassLoader loader,
|
public void applyToMainClass(GroovyClassLoader loader,
|
||||||
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
||||||
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
||||||
if (true) {
|
if (true) { // FIXME: add switch for auto config
|
||||||
addEnableAutoConfigurationAnnotation(source, classNode);
|
addEnableAutoConfigurationAnnotation(source, classNode);
|
||||||
}
|
}
|
||||||
|
// FIXME: allow the extra resolvers to be switched on (off by default)
|
||||||
|
addExtraResolvers();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addExtraResolvers() {
|
||||||
|
Map<String, Object> resolver = new HashMap<String, Object>();
|
||||||
|
resolver.put("name", "spring-milestone");
|
||||||
|
resolver.put("root", "http://repo.springframework.org/milestone");
|
||||||
|
Grape.addResolver(resolver);
|
||||||
|
resolver.put("name", "spring-snapshot");
|
||||||
|
resolver.put("root", "http://repo.springframework.org/snapshot");
|
||||||
|
Grape.addResolver(resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
|
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.bootstrap.cli.compiler.autoconfigure;
|
||||||
|
|
||||||
|
import org.codehaus.groovy.ast.ClassNode;
|
||||||
|
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||||
|
import org.springframework.bootstrap.cli.compiler.AstUtils;
|
||||||
|
import org.springframework.bootstrap.cli.compiler.CompilerAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.cli.compiler.DependencyCustomizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link CompilerAutoConfiguration} for Spring Batch.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(ClassNode classNode) {
|
||||||
|
// Slightly weird detection algorithm because there is no @Enable annotation for
|
||||||
|
// Integration
|
||||||
|
return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint")
|
||||||
|
|| classNode.getName().contains("SpringIntegration");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyDependencies(DependencyCustomizer dependencies) {
|
||||||
|
dependencies
|
||||||
|
.ifAnyMissingClasses("org.springframework.integration.Message")
|
||||||
|
.add("org.springframework.integration", "spring-integration-core",
|
||||||
|
"2.2.3.RELEASE")
|
||||||
|
.add("org.springframework.integration",
|
||||||
|
"spring-integration-dsl-groovy-core", "1.0.0.M1");
|
||||||
|
dependencies.ifAnyMissingClasses("groovy.util.XmlParser").add(
|
||||||
|
"org.codehaus.groovy", "groovy-xml", "2.1.3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void applyImports(ImportCustomizer imports) {
|
||||||
|
imports.addImports("org.springframework.integration.Message",
|
||||||
|
"org.springframework.integration.MessageChannel",
|
||||||
|
"org.springframework.integration.MessageHeaders",
|
||||||
|
"org.springframework.integration.annotation.MessageEndpoint",
|
||||||
|
"org.springframework.integration.annotation.Header",
|
||||||
|
"org.springframework.integration.annotation.Headers",
|
||||||
|
"org.springframework.integration.annotation.Payload",
|
||||||
|
"org.springframework.integration.annotation.Payloads",
|
||||||
|
"org.springframework.integration.dsl.groovy.builder.IntegrationBuilder");
|
||||||
|
}
|
||||||
|
}
|
@ -55,7 +55,7 @@ public class SampleIntegrationTests {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void clean() {
|
public static void clean() {
|
||||||
// SpringBootstrapCli.main("clean");
|
// SpringBootstrapCli.main("clean");
|
||||||
// System.setProperty("ivy.message.logger.level", "4");
|
// System.setProperty("ivy.message.logger.level", "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -63,6 +63,11 @@ public class SampleIntegrationTests {
|
|||||||
start("samples/app.groovy");
|
start("samples/app.groovy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jobSample() throws Exception {
|
||||||
|
start("samples/job.groovy");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void webSample() throws Exception {
|
public void webSample() throws Exception {
|
||||||
start("samples/web.groovy");
|
start("samples/web.groovy");
|
||||||
@ -73,4 +78,9 @@ public class SampleIntegrationTests {
|
|||||||
start("samples/service.groovy");
|
start("samples/service.groovy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void integrationSample() throws Exception {
|
||||||
|
start("samples/integration.groovy");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beansProjectDescription>
|
||||||
|
<version>1</version>
|
||||||
|
<pluginVersion><![CDATA[3.2.0.201303060654-RELEASE]]></pluginVersion>
|
||||||
|
<configSuffixes>
|
||||||
|
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||||
|
</configSuffixes>
|
||||||
|
<enableImports><![CDATA[false]]></enableImports>
|
||||||
|
<configs>
|
||||||
|
<config>src/main/resources/integration-context.xml</config>
|
||||||
|
</configs>
|
||||||
|
<configSets>
|
||||||
|
</configSets>
|
||||||
|
</beansProjectDescription>
|
@ -0,0 +1,135 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>spring-bootstrap-samples</artifactId>
|
||||||
|
<groupId>org.springframework.bootstrap</groupId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>spring-bootstrap-service-sample</artifactId>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>tomcat</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
|
<artifactId>tomcat-embed-logging-juli</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>jetty</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
<version>8.1.9.v20130131</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>javax.servlet</artifactId>
|
||||||
|
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-jsp</artifactId>
|
||||||
|
<version>8.1.9.v20130131</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>juli</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
|
<version>1.7.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>log4j</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>logback</id>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>1.9.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>objenesis</artifactId>
|
||||||
|
<groupId>org.objenesis</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
<artifactId>hamcrest-library</artifactId>
|
||||||
|
<version>1.3</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>hamcrest-core</artifactId>
|
||||||
|
<groupId>org.hamcrest</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<main.basedir>${project.basedir}/../..</main.basedir>
|
||||||
|
<start-class>org.springframework.bootstrap.sample.service.ServiceBootstrapApplication</start-class>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.bootstrap</groupId>
|
||||||
|
<artifactId>spring-bootstrap-samples</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>spring-bootstrap-integration-sample</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<main.basedir>${project.basedir}/../..</main.basedir>
|
||||||
|
<start-class>org.springframework.bootstrap.sample.service.IntegrationBootstrapApplication</start-class>
|
||||||
|
<spring.integration.version>2.2.3.RELEASE</spring.integration.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>spring-bootstrap-service</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.integration</groupId>
|
||||||
|
<artifactId>spring-integration-core</artifactId>
|
||||||
|
<version>${spring.integration.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.integration</groupId>
|
||||||
|
<artifactId>spring-integration-stream</artifactId>
|
||||||
|
<version>${spring.integration.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.springframework.bootstrap.sample.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class HelloWorldService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServiceProperties configuration;
|
||||||
|
|
||||||
|
public String getHelloMessage(String name) {
|
||||||
|
return this.configuration.getGreeting() + " " + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.springframework.bootstrap.sample.service;
|
||||||
|
|
||||||
|
import org.springframework.bootstrap.SpringApplication;
|
||||||
|
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||||
|
import org.springframework.bootstrap.service.annotation.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.ImportResource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@EnableConfigurationProperties(ServiceProperties.class)
|
||||||
|
@ComponentScan
|
||||||
|
@ImportResource("integration-context.xml")
|
||||||
|
public class IntegrationBootstrapApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
SpringApplication.run(IntegrationBootstrapApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package org.springframework.bootstrap.sample.service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.integration.annotation.MessageEndpoint;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
||||||
|
@MessageEndpoint
|
||||||
|
public class SampleEndpoint {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HelloWorldService helloWorldService;
|
||||||
|
|
||||||
|
@ServiceActivator
|
||||||
|
public Map<String, String> hello(String input) {
|
||||||
|
return Collections.singletonMap("message",
|
||||||
|
this.helloWorldService.getHelloMessage(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.bootstrap.sample.service;
|
||||||
|
|
||||||
|
import org.springframework.bootstrap.context.annotation.ConfigurationProperties;
|
||||||
|
|
||||||
|
@ConfigurationProperties(name = "service", ignoreUnknownFields = false)
|
||||||
|
public class ServiceProperties {
|
||||||
|
|
||||||
|
private String greeting = "Hello";
|
||||||
|
|
||||||
|
public String getGreeting() {
|
||||||
|
return this.greeting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGreeting(String greeting) {
|
||||||
|
this.greeting = greeting;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
logging.file: /tmp/logs/app.log
|
||||||
|
service.greeting: Hello
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:int="http://www.springframework.org/schema/integration"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||||
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
<int:channel id="input"/>
|
||||||
|
<int:service-activator input-channel="input" ref="sampleEndpoint"/>
|
||||||
|
|
||||||
|
</beans>
|
@ -0,0 +1,60 @@
|
|||||||
|
package org.springframework.bootstrap.sample.service;
|
||||||
|
|
||||||
|
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.bootstrap.SpringApplication;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.integration.Message;
|
||||||
|
import org.springframework.integration.core.MessagingTemplate;
|
||||||
|
import org.springframework.integration.support.MessageBuilder;
|
||||||
|
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic integration tests for service demo application.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class IntegrationBootstrapApplicationTests {
|
||||||
|
|
||||||
|
private static ConfigurableApplicationContext context;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void start() throws Exception {
|
||||||
|
Future<ConfigurableApplicationContext> future = Executors
|
||||||
|
.newSingleThreadExecutor().submit(
|
||||||
|
new Callable<ConfigurableApplicationContext>() {
|
||||||
|
@Override
|
||||||
|
public ConfigurableApplicationContext call() throws Exception {
|
||||||
|
return (ConfigurableApplicationContext) SpringApplication
|
||||||
|
.run(IntegrationBootstrapApplication.class);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
context = future.get(10, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void stop() {
|
||||||
|
if (context != null) {
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVanillaExchange() throws Exception {
|
||||||
|
MessagingTemplate template = new MessagingTemplate();
|
||||||
|
template.setChannelResolver(new BeanFactoryChannelResolver(context));
|
||||||
|
Message<?> result = template.sendAndReceive("input",
|
||||||
|
MessageBuilder.withPayload("Phil").build());
|
||||||
|
assertEquals("{message=Hello Phil}", result.getPayload().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -67,6 +67,11 @@
|
|||||||
<artifactId>spring-jdbc</artifactId>
|
<artifactId>spring-jdbc</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-tx</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-orm</artifactId>
|
<artifactId>spring-orm</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user