2017-07-30 205 views
0

需要專家的幫助。我是新來學習駱駝駱駝。我配置了駱駝春季啓動應用程序。現在我想添加mina2協議。我發現下面的代碼爲xml配置mina2,但是如何在我的spring啓動應用程序中添加此代碼?如何在Spring Boot應用程序中設置mina2 hl7Codec

<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 
 
\t at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:85) 
 
\t at org.apache.camel.spring.boot.CamelMainRunController$DaemonTask.run(CamelMainRunController.java:53) 
 
\t 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 
 
\t at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209) 
 
\t at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1087) 
 
\t at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3544) 
 
\t at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3275) 
 
\t at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:202) 
 
\t at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3093) 
 
\t at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3089) 
 
\t at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3112) 
 
\t at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3089) 
 
\t at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
 
\t at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3026) 
 
\t at org.apache.camel.main.Main.doStart(Main.java:129) 
 
\t at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) 
 
\t at org.apache.camel.main.MainSupport.run(MainSupport.java:168) 
 
\t at org.apache.camel.spring.boot.CamelSpringBootApplicationController.run(CamelSpringBootApplicationController.java:80) 
 
\t ... 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 
 
\t at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:723) 
 
\t at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) 
 
\t at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219) 
 
\t at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112) 
 
\t at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:118) 
 
\t at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69) 
 
\t at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:94) 
 
\t at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1278) 
 
\t at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) 
 
\t ... 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 
 
\t at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:614) 
 
\t at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:640) 
 
\t at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497) 
 
\t at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:507) 
 
\t at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:256) 
 
\t at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:299) 
 
\t at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:287) 
 
\t at org.apache.camel.component.mina2.Mina2Component.createEndpoint(Mina2Component.java:71) 
 
\t at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:116) 
 
\t at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:676) 
 
\t ... 24 more

回答

0

最後我發現我自己的問題的答案。答案是如下:

@Bean 
 
\t public CamelContext contex() { 
 
\t \t CamelContext camelContext; 
 
\t \t SimpleRegistry reg = new SimpleRegistry(); 
 
\t \t reg.put("hl7codec", new HL7MLLPCodec()); 
 
\t \t camelContext = new DefaultCamelContext(reg); 
 
\t \t return camelContext; 
 
\t \t 
 
\t }

使用此代碼。

0

由於該代碼的作品,但我把這個在CamelContextConfiguration豆

@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) { 

     } 
    }; 
} 
相關問題