Search code examples
javaspring-bootspring-integration

Dependency injection error when receiving message with @ServiceActivator


It even goes into my AnotherService, but all the other Autowired objects inside AnotherService don't seem to have injected.

@Transactional was an attempt, I also added @EnableIntegration and @EnableTransactionManagement, but without success.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class ReceiverMessageService {

    @Autowired
    private AnotherService anotherService;

    @ServiceActivator(inputChannel = "MyInputChannel")
    @Transactional
    public void messageReceiver(byte[] payload) {
        // work with payload ...
        this.anotherService.doAnything(/*myPayload*/);
    }
}

When I evaluate the autowired objects inside AnotherService I get this:

CGLIB$BOUND = false
CGLIB$CALLBACK_0 = {CglibAopProxy$DynamicAdvisedInterceptor@19413} 
CGLIB$CALLBACK_1 = {CglibAopProxy$StaticUnadvisedInterceptor@19414} 
...
...
...
...

This is the error:

org.springframework.dao.InvalidDataAccessApiUsageException: no attributes found in the request; nested exception is java.lang.IllegalStateException: no attributes found in the request

Solution

  • No thread-bound request found: Are you referring to request attributes outside of an actual web request

    So, you have a problem with an HTTP request entity outside of the HTTP thread. See if you can transfer that info via method call param instead of injection attempt of the resource which is not available in that thread any more. Or make sure you don’t change threads after receiving HTTP request.