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

Spring get bean

hmily1129 | 2013.08.24 16:00:25 댓글: 0 조회: 4163 추천: 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
11662
관리자
2003-09-20
11213
관리자
2003-09-20
20255
지구인
2010-08-27
19109
지구인
2009-09-07
13400
SOLIDH
2010-01-29
15418
엔죠라이프
2004-10-07
16521
CHOSUN
2014-01-11
2438
CHOSUN
2014-01-07
2595
CHOSUN
2014-01-07
2378
CHOSUN
2014-01-07
2047
CHOSUN
2014-01-07
1790
CHOSUN
2014-01-07
1611
CHOSUN
2014-01-07
1176
즐거운개굴
2013-09-29
3001
hmily1129
2013-09-03
4909
hmily1129
2013-08-29
5362
hmily1129
2013-08-26
4792
hmily1129
2013-08-25
3634
hmily1129
2013-08-24
4163
hmily1129
2013-08-23
4321
hmily1129
2013-08-23
3592
hmily1129
2013-08-22
1886
hmily1129
2013-08-10
1622
hmily1129
2013-08-05
2149
hmily1129
2013-08-05
2089
hmily1129
2013-07-30
1462
CHOSUN
2013-07-23
1941
모이자 모바일