Autowired 메모 사용
3504 단어 J2EE
public class SimpleMovieLister{
private MovieFinder movieFinder;
@Autowired(required=flase)
public void setMovieFinder(MovieFinder movie){
this.movieFinder = movie;
}
}
클래스마다 하나의 구조기만 Required =true로 표시됩니다.spring의 공식 문서에서 필요한 속성이라면 @required 주석을 사용하십시오
2. @Autowired의 주석을 통해list 집합이나 맵 집합을 사용하여 이 클래스의 자원을 출력하거나 사용할 수 있습니다.
public interface BeanInterface {
//
}
@Order(2)//
@Component
public class One_interface implements BeanInterface{
//
}
@Order(1)
@Component
public class Two_interface implements BeanInterface{
//
}
@Component
public class BeanInvoker {
@Autowired
private List list;
public void say(){
if(list != null && list.size() != 0)
for (BeanInterface beanInterface : list) {
System.out.println(beanInterface.getClass().getName());
}
else
System.out.println("not null");
}
}
@RunWith(BlockJUnit4ClassRunner.class)
public class TestInterface {
public TestInterface() {}
@Test
public void say(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-interface.xml");
BeanInvoker beaninvoker = ctx.getBean("beanInvoker", BeanInvoker.class);
beaninvoker.say();
}
}
/ / xml
/www.springframework.org/schema /beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
">
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
layui- 동적 렌더링 드롭다운 상자 (백그라운드에서 드롭다운 상자 값 가져오기) & 드롭다운 상자 기본 선택 설정동적 렌더 드롭다운 상자 드롭다운 상자 기본 선택 설정...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.