How to inject value into bean properties in Spring
2728 ワード
In Spring、there are three ways to inject value into bean properties. Normal way Shotcut 「p」schema See a simple Java class,which contains two properties–
Inject value within a‘
Inject value with「
Inject value by using“
コンサート
Which methods to use is totally base on personal preference,it will not affect the value inject into the bean properties.
name
and type
.Later you will use Spring to inject value into the bean properties.package com.mkyong.common;
public class FileNameGenerator {
private String name;
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
1.Normal wayInject value within a‘
value
’(and enclosed with‘property
’)
mkyong
txt
2.ShotcutInject value with「
value
」atribute.
3.「p」schemaInject value by using“
p
”schema as an atributes.
Remember declares the xmlns:p=”http://www.springframework.org/schema/p
in the Spring XML bean configration file.コンサート
Which methods to use is totally base on personal preference,it will not affect the value inject into the bean properties.