我正在使用Spring-Boot,我试图在不使用application-context.xml文件的情况下设置已实现服务的必需属性(即带有@Required标记的属性)。在我的application-context.xml文件中,服务如下所示:
<bean class="services.impl.MyServiceImpl">
<property name="property" value="value" />
</bean>
我猜这些属性在Java中看起来像这样:
protected Properties buildMyServiceImplProperties()
{
Properties myServiceImplProperties = new Properties();
myServiceImplProperties.setProperty("property", "value");
return myServiceImplProperties;
}
编辑:服务类MyService的定义如下:
package services;
public interface MyService {}
实施是:
package services.impl;
import services.DoctorService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class MyServiceImpl implements MyService {
private String value;
@Required
public void setProperty(String value) {
this.value = value;
}
}
答案 0 :(得分:0)
不确定我是否理解您的问题,但如果您想在Java Config中创建该bean,则只需要这样的内容:
@Bean
public MyService(){
MyService service = new MyServiceImpl();
service.setProperty("property", "value");
return service;
}