【发布时间】:2012-02-25 13:33:08
【问题描述】:
我最近编写了一个非常简单的 Restful 服务,部署到 JBoss AS 7。
我有一个 JAX-RS 接口被污染为(使用 scala):
@Provider
@Path("/customers")
trait ICustomerService {
@GET
@Path("/{id}")
@Produces(Array("application/xml"))
def getCustomer(@PathParam("id") id: Int): StreamingOutput
}
一个类实现它(使用 scala):
class ServiceFacade extends ICustomerService {
val ctx = new ClassPathXmlApplicationContext("orderservice.xml")
val customerService = ctx.getBean("customerService").asInstanceOf[CustomerService]
def getCustomer(id: Int): StreamingOutput = {
customerService.getCustomer(id)
}
}
问题来了。每次我从客户端浏览器发出请求时,Jboss 都会创建一个新的 ServiceFacade,因此 Spring xml 文件会被解析一次。
我是否可以在 spring 配置中自己创建 ServiceFacade 并让 JBoss 使用它而不是为每个单独的 clieng 请求创建?
非常感谢。
【问题讨论】:
标签: java spring scala jboss resteasy