2

ここで、Jerseyを使用してWebsphere8.5でRESTfulWebサービスを作成します。
また、RESTfulWebサービスにEJB3.1の容量が必要です。
次のような私の安らかなWebサービスコード:

@Stateless
@Path("/tagServiceRS/{tagid}")
@Interceptors(TestTagServiceInterceptor.class)
public class TagServiceRS implements Serializable{
    private static final long serialVersionUID = 5L;
    private static final Logger log = LoggerFactory.getLogger(TagServiceRS.class);


    @EJB
    private TagTestService tagTestService;

    @PersistenceContext(unitName = "tag-ejb")
    private EntityManager entityManager;


    @GET
    @Produces("text/plain")
    public String findTagById(@PathParam("tagid") String tagid) {
       return "TAG";
    }


    /**
     * @return the tagTestService
     */
    public TagTestService getTagTestService() {
        return tagTestService;
    }

    /**
     * @param tagTestService the tagTestService to set
     */
    public void setTagTestService(TagTestService tagTestService) {
        this.tagTestService = tagTestService;
    }

Websphere8.5に戦争を展開するとき。TagServiceRSは、RESTfulWebサービスとして正常にデプロイされました。テストしました。大丈夫です。
しかし、TagServiceRSはEJBセッションBeanとしてのデプロイに失敗しました。TagServiceRSのentityManagerフィールドとtagTestServiceフィールドはすべてnullです。 ログが表示されますが、エラーや警告のログはありません。 以下は私のTagTestServiceBeanコードです。


@Stateless
public class TagTestServiceBean implements TagTestService, Serializable {

    private static final long serialVersionUID = 5L;
    private static final Logger log = LoggerFactory.getLogger(TagTestServiceBean.class);


    @Override
    public Tag testFindTagById(Long id) {
        log.info("testFindTagById ++++++++++++++++++++++++++++++++++++++++ invoked for id: {}", id);
        return new Tag();
    }

}

    @Remote
public interface TagTestService extends Serializable {

    /**
     * @param id
     *            the ID from database
     * @return a tag, may null
     */
    Tag testFindTagById(Long id);

}

答えがあれば。どうもありがとう。

4

1 に答える 1

0

注釈を から@EJBに変更します@Resource

@Resource
private TagTestService tagTestService;

クラス自体に注釈を付ける必要はありません@Stateless

さらに、JAX-RS ルート リソースおよびプロバイダー クラスには、JCDI 指定のスコープが必要です。スコープは、JCDI マネージド Bean のライフサイクルを制御します。ルート リソース クラスは、@javax.enterprise.context.RequestScoped などの任意の有効なスコープを持つことができます。これにより、JAX-RS ルート リソース クラスは、非 JCDI 対応アプリケーションと同じように動作します。javax.ws.rs.core.Application サブクラスと JAX-RS プロバイダーには、@javax.enterprise.context.ApplicationScoped アノテーションが必要です。

詳細はこちら

于 2013-03-16T22:07:57.150 に答える