시크밤
주간 베스트 월간 베스트 3개월 베스트 베스트 게시물
연길시 신화서점 조선말 도서

Spring get bean

hmily1129 | 2013.08.24 16:00:25 댓글: 0 조회: 4167 추천: 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
11732
관리자
2003-09-20
11275
관리자
2003-09-20
20336
지구인
2010-08-27
19200
지구인
2009-09-07
13490
SOLIDH
2010-01-29
15481
엔죠라이프
2004-10-07
16592
CHOSUN
2014-01-11
2442
CHOSUN
2014-01-07
2598
CHOSUN
2014-01-07
2384
CHOSUN
2014-01-07
2052
CHOSUN
2014-01-07
1794
CHOSUN
2014-01-07
1613
CHOSUN
2014-01-07
1179
즐거운개굴
2013-09-29
3003
hmily1129
2013-09-03
4911
hmily1129
2013-08-29
5372
hmily1129
2013-08-26
4794
hmily1129
2013-08-25
3638
hmily1129
2013-08-24
4167
hmily1129
2013-08-23
4324
hmily1129
2013-08-23
3598
hmily1129
2013-08-22
1892
hmily1129
2013-08-10
1626
hmily1129
2013-08-05
2155
hmily1129
2013-08-05
2094
hmily1129
2013-07-30
1472
CHOSUN
2013-07-23
1945
모이자 모바일