【发布时间】:2020-02-27 20:51:21
【问题描述】:
我遇到了一个异常: 没有为依赖项 [java.lang.String] 找到符合条件的 bean:预计至少有 1 个符合自动装配候选条件的 bean。
在 beans.xml 中
<bean id = "database" class = "com.price.compare.service.DAO" scope="singleton">
<constructor-arg index="0" type = "java.lang.String" value="localhost"/>
<constructor-arg index="1" type = "java.lang.String" value="5432"/>
</bean>
DAO.java
@零件 公共类 DAO { 私有最终字符串主机; 私有最终字符串端口; 公共 DAO(字符串主机,字符串端口){ this.host = 主机; this.port = 端口; } @PostConstruct 公共无效初始化(){ // 自定义初始化逻辑 } }【问题讨论】: