使用spring DM的项目迁移到Aries Blueprint时,出现bean 属性值无法正确转换的问题

During the migration of a project using spring DM to Aries Blueprint, there is a problem that the bean property value cannot be properly converted

我正在迁移 spring-DM 到 ariesblueprint

使用 java11 和 karaf 4.2.14

同时,aries blueprint 遇到了context.xml的值没有找到合适的转换器的问题,它定义了Apache Mina的defaultLocalAddress。

15:25:43.199 ERROR [features-3-thread-1] Unable to start container for blueprint bundle test/0.0.1.SNAPSHOT
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: defaultLocalAddress, getter: class org.apache.mina.transport.socket.nio.NioSocketAcceptor.getDefaultLocalAddress(), setter: [class org.apache.mina.transport.socket.nio.NioSocketAcceptor.setDefaultLocalAddress(class java.net.InetSocketAddress), class org.apache.mina.core.service.AbstractIoAcceptor.setDefaultLocalAddress(class java.net.SocketAddress)]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:818) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:784) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:765) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:699) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:666) ~[!/:1.10.3]
        at org.apache.aries.blueprint.di.AbstractRecipe.call(AbstractRecipe.java:81) ~[!/:1.10.3]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:90) ~[!/:1.10.3]
        at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:62) ~[!/:1.10.3]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:108) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:810) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:784) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:765) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:699) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:666) ~[!/:1.10.3]
        at org.apache.aries.blueprint.di.AbstractRecipe.call(AbstractRecipe.java:81) ~[!/:1.10.3]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:90) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:360) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:190) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:737) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:433) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:298) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:335) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:288) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:284) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:274) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.addingBundle(BlueprintExtender.java:237) [!/:1.10.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerAdding(BundleHookBundleTracker.java:487) [!/:1.10.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerAdding(BundleHookBundleTracker.java:433) [!/:1.10.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.trackAdding(BundleHookBundleTracker.java:749) [!/:1.10.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.trackInitial(BundleHookBundleTracker.java:674) [!/:1.10.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker.open(BundleHookBundleTracker.java:159) [!/:1.10.3]
        at org.apache.aries.util.tracker.RecursiveBundleTracker.open(RecursiveBundleTracker.java:106) [!/:1.10.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.serviceFound(BlueprintExtender.java:138) [!/:1.10.3]
        at org.apache.aries.util.tracker.SingleServiceTracker.update(SingleServiceTracker.java:174) [!/:1.10.3]
        at org.apache.aries.util.tracker.SingleServiceTracker.findMatchingReference(SingleServiceTracker.java:132) [!/:1.10.3]
        at org.apache.aries.util.tracker.SingleServiceTracker.access0(SingleServiceTracker.java:32) [!/:1.10.3]
        at org.apache.aries.util.tracker.SingleServiceTracker.serviceChanged(SingleServiceTracker.java:61) [!/:1.10.3]
        at org.apache.felix.framework.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:990) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:838) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.EventDispatcher.fireServiceEvent(EventDispatcher.java:545) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4595) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.Felix.registerService(Felix.java:3587) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:322) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.aries.proxy.impl.ProxyManagerActivator.start(ProxyManagerActivator.java:66) [!/:1.1.12]
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2240) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2146) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984) [org.apache.felix.framework-5.6.12.jar:?]
        at org.apache.karaf.features.internal.service.BundleInstallSupportImpl.startBundle(BundleInstallSupportImpl.java:165) [!/:?]
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1154) [!/:?]
        at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:1044) [!/:?]
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1063) [!/:?]
        at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread(FeaturesServiceImpl.java:998) [!/:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: org.osgi.service.blueprint.container.ComponentDefinitionException: No converter available to convert value :8000 into a form applicable for the setters of property defaultLocalAddress
        at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:672) ~[!/:1.10.3]
        at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:418) ~[!/:1.10.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:816) ~[!/:1.10.3]
        ... 60 more

它是我网络的一部分-context.xml。

<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor">
    <property name="defaultLocalAddress" value=":8000"/>
    <property name="handler" ref="minaHandler"/>
    <property name="reuseAddress" value="true"/>
    <property name="filterChainBuilder" ref="filters"/>
</bean>

它在 SpringDM 中运行良好。

短语本身似乎没有改变,所以我就按原样使用它。

有没有我忘记了什么或者做了什么蠢事?

如果问题奇怪或愚蠢,请告诉我。

我认为 Aries 不支持 InetSocketAddress 的本机类型转换器。

您可以显式创建一个 InetSocketAddress:

的新实例
<bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor">
    <property name="defaultLocalAddress" value=":8000">
      <bean class="java.net.InetSocketAddress">
        <argument value="8000"/>
      </bean>
    <property name="handler" ref="minaHandler"/>
    <property name="reuseAddress" value="true"/>
    <property name="filterChainBuilder" ref="filters"/>
</bean>

或者注册你自己的类型转换器。

您应该实现 org.osgi.service.blueprint.container.Converter 并使用 <type-converter>

注册它

参见: