开发者社区> 问答> 正文

OSGI Blueprint里面配置class,set方法必须是void的吗??报错

在Blueprint.xml配置文件里面

<bean id="nginx" class="com.lala.osgi.server.ApacheServer">
        <property name="id" value="10010"/>
        <property name="name" value="1.19.2"/>
        <property name="port" value="80"/>
        <property name="address" value="127.0.0.1"/>
</bean>



要配置这个class,这些属性必须要有get,set方法

现在的问题是:我的set方法不是void的

比如说:

public HttpServer setPort(Integer port) 
	{
		this.port = port;
		return this;
	}



这种,写法 在spring是可以的。但是在osgi的blueprint里面不行,一直报错:

org.osgi.service.blueprint.container.ComponentDefinitionException: No setter for port property

请问,这种问题如何解决

(PS, set方法不能改,不能改成void的)

展开
收起
爱吃鱼的程序员 2020-06-12 14:23:42 462 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    默认不支持非void方法的注入,需要加上:

    ext:field-injection= "true"

    就可以了

    如:

    <bean id= "configuration" class= "org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration" ext:field-injection= "true"/ >

    一般的做法是,如果是玩链式调用,会写成两个方法:

    publicvoidsetPort(...){...}  //专用于set/get

    publicHttpServerport(...){...; returnthis;}   //链式

    祝你好运。。。


    关键是:setPort方法以及被占用了,而且不是void返回值

    2020-06-12 14:23:59
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载