JaxRS使用构造函数设置资源类

时间:2015-09-08 12:44:25

标签: java web-services rest jax-rs

我有一个jaxrs服务器,我想设置一个资源类。问题是我的类有一个构造函数,我在其中注入另一个对象的另一个依赖项。

      final JAXRSServerFactoryBean serverFactory = new JAXRSServerFactoryBean();
      serverFactory.setResourceClasses( MessageService.class);
      serverFactory.setResourceProvider( MessageService.class,
            new SingletonResourceProvider( new MessageService() ) );
      serverFactory.setAddress( "http://localhost:8080/service/" );

      serverFactory.setProvider( JacksonJsonProvider.class );
      serverFactory.create();

我的MessageService课程:

public class MessageService
{

   private final MessageProvider mp;


   public MessageService( final MessageProvider messageProvider )
   {
      this.mp = messageProvider;
   }
}

我收到错误:resource class MessageService has no valid constructor

你能帮我解决这个问题吗?

0 个答案:

没有答案