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个回答

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

在没有加上注解的情况下

beans-config.xml内容呢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问