Skip to content

Reconsider PR #2769 #3130

Closed
Closed
@garyrussell

Description

@garyrussell

#2769

Deferring the creation of integration components prevents injection:

@SpringBootApplication
public class So59469573Application {

	public static void main(String[] args) {
		SpringApplication.run(So59469573Application.class, args);
	}

}

@Component
class Integration {

	@InboundChannelAdapter(channel = "channel", autoStartup = "true",
			poller = @Poller(fixedDelay = "5000"))
	public String foo() {
		return "foo";
	}

	@ServiceActivator(inputChannel = "channel")
	public void handle(String in) {
		System.out.println(in);
	}

}

@RestController
class Rest {

	@Autowired
	@Qualifier("integration.foo.inboundChannelAdapter")
	SourcePollingChannelAdapter adapter;

	@PostMapping("/foo/{command}")
	public void trigger(@PathVariable String command) {
		if ("start".equals(command)) {
			adapter.start();
		}
	}

}
Description:

Field adapter in com.example.demo.Rest required a bean of type 'org.springframework.integration.endpoint.SourcePollingChannelAdapter' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)
	- @org.springframework.beans.factory.annotation.Qualifier(value=integration.foo.inboundChannelAdapter)


Action:

Consider defining a bean of type 'org.springframework.integration.endpoint.SourcePollingChannelAdapter' in your configuration.

I am sure that was not intended although the reason for the change is valid too.

Work around is to use a control bus:

@SpringBootApplication
@IntegrationComponentScan
public class So59469573Application {

	public static void main(String[] args) {
		SpringApplication.run(So59469573Application.class, args);
	}

}

@Component
class Integration {

	public Integration() {
		super();
	}

	@InboundChannelAdapter(channel = "channel", autoStartup = "false",
			poller = @Poller(fixedDelay = "5000"))
	public String foo() {
		return "foo";
	}

	@ServiceActivator(inputChannel = "channel")
	public void handle(String in) {
		System.out.println(in);
	}

	@ServiceActivator(inputChannel = "controlChannel")
	@Bean
	public ExpressionControlBusFactoryBean controlBus() {
		return new ExpressionControlBusFactoryBean();
	}

}

@MessagingGateway(defaultRequestChannel = "controlChannel")
interface Control {

	void send(String control);
}

@RestController
class Rest {

	@Autowired
	Control control;

	public Rest() {
		super();
	}

	@PostMapping("/foo/{command}")
	public void trigger(@PathVariable String command) {
		if ("start".equals(command)) {
			control.send("@'integration.foo.inboundChannelAdapter'.start()");
		}
	}

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions