의문
회사에서 코드를 짜던 중 component, controller, service, mapper등이 아니라서 마음대로 @autowired, @resource 등을 해서 가져다가 쓸 수 없었다. 그래서 bean 등록이 안되는 부분에 mapper, service등을 가져와 사용하고 싶을 때는 어떻게 해야할까?
답
TestMapper mapper = (TestMapper) ApplicationContextProvider.getApplicationContext().getBean("testMapper");
List<Map> List = mapper.test();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
TestMapper testMapper = (TestMapper) ctx.getBean("testMapper");
'Today I Learned > Spring' 카테고리의 다른 글
[Spring] redirect 시, URL에 파라미터 붙는 이유 (0) | 2025.06.28 |
---|---|
[Security] @Secured, @PreAuthorize, @PostAuthorize (0) | 2025.05.27 |
[Spring] React 라우팅을 위한 SPA 서버 세팅 (0) | 2025.04.20 |
[Spring] RestTemplate (0) | 2025.04.09 |
[Spring] getSession(), getSession(true), getSession(false) (0) | 2023.03.06 |