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

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;
    //不应该是这样的吗?

    评论

报告相同问题?