我似乎在配置Spring MVC后端以接收和发送TCP消息时遇到了一些麻烦。查看用户在此问题中建议的配置 - how to plug a TCP-IP client server in a spring MVC application - 我尝试将此配置放入我的root-context.xml
。但是,对于所有标记,它会显示一条消息,例如:
Unable to locate Spring NamespaceHandler for element 'int-ip:tcp-outbound-gateway' of schema namespace 'http://www.springframework.org/schema/integration/ip'
int-ip:tcp-outbound-gateway
和int:gateway
都显示cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'int:gateway'
(将int:gateway
替换为int-ip:tcp-outbound-gateway
)。
这是我的root-context.xml
文件:
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd
http://www.springframework.org/schema/integration/ http://www.springframework.org/schema/integration/spring-integration.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<int:gateway id="gw"
service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
default-request-channel="input"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="1234"
single-use="true"
so-timeout="10000"/>
<int:channel id="input" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
request-timeout="10000"
remote-timeout="10000"/>
<int:transformer id="clientBytes2String"
input-channel="clientBytes2StringChannel"
expression="new String(payload)"/>
</beans>
我做错了什么?另外,关于如何使用Spring发送和接收TCP通信的一些一般提示将不胜感激:)
答案 0 :(得分:1)
您的类路径上似乎没有spring-integration-ip
和spring-integration-core
个罐子。您需要根据应用服务器的要求将它们捆绑到战争中或以其他方式在类路径中使用。