我想要定义一个bean和@Autowire org.springframework.jdbc.object.StoredProcedure需要2个构造函数。有没有一种方法可以传递构造函数参数,同时连接这些bean?下面是我的代码:如何@构造函数@Autowire bean
@Component("procedure")
public class ExecuteStoreProcedure extends AbstractImutableDAO{
@Autowired
private StoredProcedure procedure;
......
}
这里的StoredProcedure有一个构造函数传递的JdbcTemplate和程序名称,它是动态的。
您打算通过哪种方式传递jdbctemplate和过程名称?为什么不在Spring XML配置中创建特定的bean?作为硬核解决方案,您可以注入配置的FactoryBean(http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-extension-factorybean)。 – Taky
我正在寻找使用注释而不是xml文件进行配置(不确定此选项在Spring中是否可用),我的过程名称也是动态的,它将成为类中的方法的参数 – user1917435
因此,您的问题是如何添加StoredProcedure到ApplicationContext中?如果StoredProcedure是第三方类,则可以扩展它,并用适当的方式标注新类。 – Taky