诗和远方1990 2017-06-20 02:12 采纳率: 0%
浏览 1677

Spring自动类型绑定注入中使用autowire=“byType”不生效,无法绑定

package com.huangwz.spring.SpringDemo6;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

public class HelloBean {
private String helloWord;
private Date date;
public String getHelloWord() {
return helloWord;
}
public void setHelloWord(String helloWord) {
this.helloWord = helloWord;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}

}

package com.huangwz.spring.SpringDemo6;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringDemo {

public static void main(String[] args) {
    ApplicationContext context=new ClassPathXmlApplicationContext("beans-config.xml");
    HelloBean helloBean=(HelloBean) context.getBean("helloBean1");
    System.out.println("word="+helloBean.getHelloWord());
    System.out.println("Date="+helloBean.getDate());
}

}



  • 写回答

3条回答 默认 最新

  • IT界的渣 2017-06-20 06:15
    关注

    @Autowired
    private service|dao sd;
    //不应该是这样的吗?

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题