J'ai un SpringBootApplication qui est abonné au courtier MQTT. Les messages MQTT doivent être enregistrés dans la base de données, mais je ne peux pas accéder à mon service @Autowired.Spring - Accès au service @Autowired de AbstractMessageHandler
Exception je reçois:
Field deviceService in com.example.MqttMessageHandler required a bean of type 'com.example.service.DeviceService' that could not be found.
MQTTApiApplication.java
@SpringBootApplication(scanBasePackages = "{com.example}")
public class MQTTApiApplication {
public static void main(String[] args) {
SpringApplicationBuilder(MQTTApiApplication.class)
.web(false).run(args);
}
@Bean
public IntegrationFlow mqttInFlow() {
return IntegrationFlows.from(mqttInbound())
.handle(new MqttMessageHandler())
.get();
}
}
MqttMessageHandler.java
public class MqttMessageHandler extends AbstractMessageHandler {
@Autowired
DeviceService deviceService;
@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
deviceService.saveDevice(new Device());
}
}
Oui, je l'ai ajouté un @component notation, mais obtenez toujours la même erreur. J'accède au service depuis RestController normalement. – mkdeki
Et DeviceService? –
Lorsque je mets DeviceService dans RestController, je peux accéder au DeviceService (qui est Autowired). Le problème est que je ne peux pas accéder aux Services/Contrôleurs Autowired à partir de MqttMessageHandler. – mkdeki