Fix Build and upgrade fully to Boot 2.0

Some tests still ignored.

Also adds draft functional bean registration support. The AWS sample
is using that now (it starts up 4x faster in AWS). To activate the
functional beans user has to supply a main class of type
ApplicationContextInitializer.
This commit is contained in:
Dave Syer
2018-06-21 13:00:46 +01:00
parent 00e2b749d2
commit 4c9627aee3
23 changed files with 896 additions and 54 deletions

View File

@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.11.RELEASE</version>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

View File

@@ -18,33 +18,48 @@ package example;
import java.util.function.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.function.context.FunctionRegistration;
import org.springframework.cloud.function.context.FunctionType;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.GenericApplicationContext;
@SpringBootApplication
@EnableConfigurationProperties(Properties.class)
public class Config {
public class Config implements ApplicationContextInitializer<GenericApplicationContext> {
private Properties props;
@Autowired
public Config() {
}
public Config(Properties props) {
this.props = props;
}
@Bean
public Function<Foo, Bar> function() {
return value -> new Bar(value.uppercase()
+ (props.getFoo() != null ? "-" + props.getFoo() : ""));
return value -> new Bar(
value.uppercase() + (props.getFoo() != null ? "-" + props.getFoo() : ""));
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Config.class, args);
}
@Override
public void initialize(GenericApplicationContext context) {
Properties properties = new Properties();
this.props = properties;
context.registerBean(Properties.class, () -> properties);
context.registerBean("function", FunctionRegistration.class,
() -> new FunctionRegistration<Function<Foo, Bar>>(function())
.type(FunctionType.from(Foo.class).to(Bar.class).getType()));
}
}
class Foo {