1.接口注入
2.getter,setter注入
3.构造器注入
1.接口注入
2.setter注入
<bean id="book" class="com.property.Book">
<property name="bookName" value="java核心技术"></property>
</bean>
package com.property;
public class Book {
private String bookName;
public void setbookName(String bookName){
this.bookName = bookName;
}
public void demoBook(){
System.out.println("..........."+this.bookName);
}
}
3.构造器注入
package com.property;
public class Property {
private String name;
public Property(String name){
this.name = name;
}
public void test(){
System.out.println("............."+name);
}
}
<bean id="property" class="com.chen.property.Property">
<constructor-arg name="name" value="java">
</constructor-arg>
</bean>
或者是
<bean id="property" class="com.property.Property">
<constructor-arg index="0" value="java" >
</constructor-arg>
</bean>
接口注入
package com.hanson.ssm.service;
import java.util.List;
import java.util.Map;
import com.hanson.ssm.pojo.Clothes;
public interface ClothesService {
public List<Clothes> findClothesList();
}
@Service
public class ClothesServiceImpl implements ClothesService{
@Override
public List<Clothes> findClothesList() {
List<Clothes> clothesList = clothesCustomMappers.findClothesList();
return clothesList;
}
}
@Autowired
private ClothesService clothesService;
package com.hanson.ssm.service;
import java.util.List;
import java.util.Map;
import com.hanson.ssm.pojo.Clothes;
public interface ClothesService {
public List<Clothes> findClothesList();
}
@Service
public class ClothesServiceImpl implements ClothesService{
@Override
public List<Clothes> findClothesList() {
List<Clothes> clothesList = clothesCustomMappers.findClothesList();
return clothesList;
}
}
@Autowired
private ClothesService clothesService;
@Autowired
private ClothesService clothesService;