주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
꽃배달 한국, 중국 전지역배송

Spring get bean

hmily1129 | 2013.08.24 16:00:25 댓글: 0 조회: 4169 추천: 0
분류웹 프로그래밍 https://life.moyiza.kr/itstudy/2001793

control에서 bean객체 얻어오기

1. web.xml셋팅
 <servlet-mapping>
  <servlet-name>test2</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>



2.
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpSession session = request.getSession();
   ServletContext conext = session.getServletContext();
  WebApplicationContext wContext = WebApplicationContextUtils.getWebApplicationContext(conext);
  mybean sBean = (mybean)wContext.getBean("sampleBean");

or

WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
 mybean sBean = (mybean) ctx.getBean("sampleBean");
 


추천 (0) 선물 (0명)
IP: ♡.118.♡.3
3,006 개의 글이 있습니다.
제목 글쓴이 날짜 조회
관리자
2003-09-20
11752
관리자
2003-09-20
11289
관리자
2003-09-20
20359
지구인
2010-08-27
19219
지구인
2009-09-07
13518
SOLIDH
2010-01-29
15493
엔죠라이프
2004-10-07
16606
CHOSUN
2014-01-11
2444
CHOSUN
2014-01-07
2599
CHOSUN
2014-01-07
2386
CHOSUN
2014-01-07
2053
CHOSUN
2014-01-07
1795
CHOSUN
2014-01-07
1615
CHOSUN
2014-01-07
1180
즐거운개굴
2013-09-29
3003
hmily1129
2013-09-03
4913
hmily1129
2013-08-29
5372
hmily1129
2013-08-26
4795
hmily1129
2013-08-25
3639
hmily1129
2013-08-24
4169
hmily1129
2013-08-23
4325
hmily1129
2013-08-23
3601
hmily1129
2013-08-22
1893
hmily1129
2013-08-10
1626
hmily1129
2013-08-05
2156
hmily1129
2013-08-05
2095
hmily1129
2013-07-30
1472
CHOSUN
2013-07-23
1945
모이자 모바일