如何在 Spring 引导应用程序中设置 mina2 hl7Codec
How to setup mina2 hl7Codec in Spring Boot Application
需要专家的帮助。我是新来学习apcahe骆驼的。我已将骆驼配置为 spring 启动应用程序。现在我想添加 mina2 协议。我在下面找到了为 xml 配置 mina2 的代码,但是如何在我的 spring 启动应用程序中添加它?
<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="iso-8859-1"/>
</bean>
如果我不添加此配置,它将通过以下异常:
Exception in thread "CamelMainRunController" java.lang.RuntimeException: org.apache.camel.FailedToCreateRouteException: Failed to create route route2: Route(route2)[[From[mina2:tcp://0.0.0.0:4001?sync=true&codec... because of Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:85)
at org.apache.camel.spring.boot.CamelMainRunController$DaemonTask.run(CamelMainRunController.java:53)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route2: Route(route2)[[From[mina2:tcp://0.0.0.0:4001?sync=true&codec... because of Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1087)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3544)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3275)
at org.apache.camel.impl.DefaultCamelContext.access[=12=]0(DefaultCamelContext.java:202)
at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3093)
at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3089)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3112)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3089)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3026)
at org.apache.camel.main.Main.doStart(Main.java:129)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:168)
at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:80)
... 2 more
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:723)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:118)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:94)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1278)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204)
... 16 more
Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:614)
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:640)
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497)
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:507)
at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:256)
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:299)
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:287)
at org.apache.camel.component.mina2.Mina2Component.createEndpoint(Mina2Component.java:71)
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:116)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:676)
... 24 more
我终于找到了自己的问题答案。答案如下:
@Bean
public CamelContext contex() {
CamelContext camelContext;
SimpleRegistry reg = new SimpleRegistry();
reg.put("hl7codec", new HL7MLLPCodec());
camelContext = new DefaultCamelContext(reg);
return camelContext;
}
使用此代码。
感谢代码有效,但我将它放在 CamelContextConfiguration Bean 中
@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
public void beforeApplicationStart(CamelContext camelContext) {
final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry();
final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry();
compositeRegistry.addRegistry(camelContext.getRegistry());
compositeRegistry.addRegistry(registry);
((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
registry.put("hl7codec", new HL7MLLPCodec());
}
@Override
public void afterApplicationStart(CamelContext camelContext) {
}
};
}
需要专家的帮助。我是新来学习apcahe骆驼的。我已将骆驼配置为 spring 启动应用程序。现在我想添加 mina2 协议。我在下面找到了为 xml 配置 mina2 的代码,但是如何在我的 spring 启动应用程序中添加它?
<bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
<property name="charset" value="iso-8859-1"/>
</bean>
如果我不添加此配置,它将通过以下异常:
Exception in thread "CamelMainRunController" java.lang.RuntimeException: org.apache.camel.FailedToCreateRouteException: Failed to create route route2: Route(route2)[[From[mina2:tcp://0.0.0.0:4001?sync=true&codec... because of Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:85)
at org.apache.camel.spring.boot.CamelMainRunController$DaemonTask.run(CamelMainRunController.java:53)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route2: Route(route2)[[From[mina2:tcp://0.0.0.0:4001?sync=true&codec... because of Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1087)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3544)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3275)
at org.apache.camel.impl.DefaultCamelContext.access[=12=]0(DefaultCamelContext.java:202)
at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3093)
at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3089)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3112)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3089)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3026)
at org.apache.camel.main.Main.doStart(Main.java:129)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:168)
at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:80)
... 2 more
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: mina2://tcp://0.0.0.0:4001?codec=%23hl7codec&sync=true due to: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:723)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80)
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112)
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:118)
at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69)
at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:94)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1278)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204)
... 16 more
Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: codec as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.mina.filter.codec.ProtocolCodecFactory with value #hl7codec
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:614)
at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:640)
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497)
at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:507)
at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:256)
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:299)
at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:287)
at org.apache.camel.component.mina2.Mina2Component.createEndpoint(Mina2Component.java:71)
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:116)
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:676)
... 24 more
我终于找到了自己的问题答案。答案如下:
@Bean
public CamelContext contex() {
CamelContext camelContext;
SimpleRegistry reg = new SimpleRegistry();
reg.put("hl7codec", new HL7MLLPCodec());
camelContext = new DefaultCamelContext(reg);
return camelContext;
}
使用此代码。
感谢代码有效,但我将它放在 CamelContextConfiguration Bean 中
@Bean
CamelContextConfiguration contextConfiguration() {
return new CamelContextConfiguration() {
@Override
public void beforeApplicationStart(CamelContext camelContext) {
final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry();
final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry();
compositeRegistry.addRegistry(camelContext.getRegistry());
compositeRegistry.addRegistry(registry);
((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
registry.put("hl7codec", new HL7MLLPCodec());
}
@Override
public void afterApplicationStart(CamelContext camelContext) {
}
};
}