---
title: "在Servlet获取spring管理的java对象"
author: "sshzhangwg"
date: "2013-05-22T17:00:13Z"
tags: []
categories: ["Web前端"]
slug: "servlet-spring-java"
draft: false
lastmod: "2013-05-22T17:00:29Z"
id: 1873532
url: "https://aiappfine.iteye.com/blog/1873532"
---

在Servlet获取spring管理的java对象：

 

```
private ConfigService getService() {
		if (cfgService == null) {
			WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
			cfgService = (ConfigService) context.getBean("configService");
		}
		return cfgService;
	}
```