我最近写了一个非常简单的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请求创建?
非常感谢。
答案 0 :(得分:0)
您正在为ServiceFacade的每个实例创建创建一个新的Spring上下文,尝试注入上下文或创建单例。我不相信JAX-RS或RestEasy只保证创建一个带注释类的实例。
另外,我自己刚刚开始使用Scala,但是你不应该将注释放在实现而不是特性上吗?