Spring Integration无法自动装配字段

时间:2017-03-27 12:53:37

标签: java spring spring-mvc spring-integration

我已阅读TCP-Server-Client并尝试运行我的示例,但我收到以下错误:

@Controller
public class HelloWorldController {

    @Autowired
    SimpleGateway gw;

    @RequestMapping(value = { "/", "/home", "/frontend" }, method = RequestMethod.GET)
    public String homePage(Locale locale, ModelMap model) {

        gw.send("test");

        return "frontend";
    }

}

我的控制器:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">

    <context:property-placeholder />

    <!-- Client side -->
    <int:gateway id="gw"
        service-interface="com.example.myapp.integration.SimpleGateway"
        default-request-channel="input"/>

    <!-- Create a connection for the client gateway that uses the same Stx-Etx deserializer to turn the stream
    into the appropriate content (it looks for the Stx byte, extracts anything between it and the Etx byte). We
    don't specify the serializer (although we could) because the unit test explicitly shows how the content
    to be sent is wrapped by the Stx and Etx bytes. -->
    <int-ip:tcp-connection-factory id="client"
        type="client"
        host="localhost"
        port="50001"
        single-use="true"
        so-timeout="10000"
        deserializer="connectionSerializeDeserialize"/>

    <int:channel id="input" />

    <int-ip:tcp-outbound-gateway id="outGateway"
        request-channel="input"
        reply-channel="clientBytes2StringChannel"
        connection-factory="client"
        request-timeout="10000"
        reply-timeout="10000"/>

    <int:channel id="clientBytes2StringChannel"/>

    <int:object-to-string-transformer id="clientBytes2String"
        input-channel="clientBytes2StringChannel" />

    <!-- Server side -->
    <!-- When creating the socket factory on the server side, we specify both the serializer and deserializer
    which deals with both accepting a stream formatted with the Stx-Etx bytes as well as sending a stream
    formatted with the Stx-Etx bytes. -->
    <int-ip:tcp-connection-factory id="serverConnectionFactory"
        type="server"
        port="65535"
        serializer="connectionSerializeDeserialize"
        deserializer="connectionSerializeDeserialize"/>


    <bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer"/>


    <int-ip:tcp-inbound-gateway id="gatewayCrLf"
        connection-factory="serverConnectionFactory"
        request-channel="incomingServerChannel"
        error-channel="errorChannel"/>

    <!-- We leave a message listener off of this channel on purpose because we hook
    one up before the test actually runs (see the unit test associated with this
    context file) -->
    <int:channel id="incomingServerChannel" />

</beans>

我的xml配置:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.example.myapp")
public class HelloWorldConfiguration extends WebMvcConfigurerAdapter {
   ...
}

我还没想通,如果需要任何其他附加配置文件。

编辑1: 我的配置文件:

og:url

2 个答案:

答案 0 :(得分:1)

您需要导入XML配置。

@ImportResource("foo.xml")添加到您的@Configuration课程。

或者,使用@Bean而不是XML添加Spring Integration配置。

答案 1 :(得分:0)

您好像没有指定组件扫描位置。尝试将以下标记添加到XML。

<context:component-scan base-package="<package-to-scan-under-spring-servlet>" />