ejb注入

ev7lccsx  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(262)

我正在为jboss应用程序更新一些遗留代码,遇到了一些麻烦。我有两个ejbbean,personbean和clientbean。clientbean负责处理特定于客户端的服务。clientbean被注入personbean的一个示例,它用这个示例作为委托将请求传递给服务器端服务。我遇到的问题是,这两个bean还实现了一个loginservice接口,该接口也需要注入。我想要的是personbean的一个示例作为loginservice被注入clientbean,但是我最终将clientbean注入到它自己。
我需要做什么来正确定义这个ejbMap?
clientserviceproviderbean:

@Stateless(name = "ClientServiceProvider")
@Local({ ClientServiceProvider.class, LoginService.class })
public class ClientServiceProviderBean implements ClientServiceProvider, LoginService
{
    @EJB(name = "personService")
    protected PersonService personService;  

    @EJB(name = "loginService")
    protected LoginService loginService;

    @Override
    public LoginDTO getLoggedInUser()
    {
        LoginDTO loginDTO = loginService.getLoggedInUser();
        return loginDTO;
    }

    @Override
    public Long activateSession(String applicationName, String ipAddress)
    {
        return personService.activateSession(applicationName, ipAddress);
    }    
}

personservicebean:

@Stateless(name = "PersonService")
@Local({ PersonService.class })
@Remote({ RemotePersonService.class })
public class PersonServiceBean implements PersonService, RemotePersonService, LoginService
{
    @Override
    @RolesAllowed({ "authenticated" })
    public Long activateSession(String applicationName, String ipAddress)
    {
        Person p = getCallerAsPerson(entityManager, context.getCallerPrincipal());
        SessionActivity sessionActivity = new SessionActivity(p.getId(), applicationName, true, ipAddress);
        sessionActivity = save(entityManager, sessionActivity);
        return sessionActivity.getId();
    }

    @Override
    @PermitAll
    public LoginDTO getLoggedInUser()
    {
        Principal p = context.getCallerPrincipal();
        if (p != null && !"unauthenticated".equals(p.getName()))
        {
            try
            {
                Person person = getCallerAsPerson(entityManager, p);
                if (person != null)
                {
                    return createLoginDTO(person);
                }
            }
            catch (javax.persistence.NoResultException e)
            {
            }
        }
        return null;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题