Spring Integration
Introduction
Integrating the framework with Spring is very simple and can be done with only 4 lines of key code.
How to Install
This module is optional and should be added in pom.xml when needed.
see https://central.sonatype.com/artifact/com.iohao.net/extension-spring
pom.xml
<dependency>
<groupId>com.iohao.net</groupId>
<artifactId>extension-spring</artifactId>
<version>${ionet.version}</version>
</dependency>
Example Source Code
see https://github.com/iohao/ionet-examples
path : ionet-spring-example
- OneApplication
- OneClient
Startup Class
- code 4: start Spring.
- code 11~14: let Spring manage actions.
As shown, integration is simple with 4 key lines.
@SpringBootApplication
public class OneApplication {
static void main(String[] args) {
SpringApplication.run(OneApplication.class, args);
...
new RunOne()
...
.startup();
}
@Bean
public ActionFactoryBeanForSpring actionFactoryBean() {
return new ActionFactoryBeanForSpring();
}
}
Action
- code 1: let Spring manage action class.
- code 4: injected by Spring.
@Component
@ActionController(MyCmd.cmd)
public class MyAction {
final MyService service;
private MyAction(MyService service) {
this.service = service;
}
@ActionMethod(MyCmd.getTime)
private String getTime() {
return service.getTime();
}
}
@Service
public class MyService {
public String getTime() {
return ...
}
}
Summary
As you can see, framework and Spring integration is simple with only 4 lines.
@Bean
public ActionFactoryBeanForSpring actionFactoryBean() {
return new ActionFactoryBeanForSpring();
}
Interesting point
The framework supports hybrid integration.
What does that mean?
Even if Spring integration is enabled, it does not mean all action classes must be managed by Spring. If an action is not managed by Spring, it still works normally as a regular Java action class.