简体   繁体   中英

Correct Configuration for JSF EJB application using remote interface

I'm creating a java class library and EJB module as a user authentication application which can be used by stand alone clients by calling the remote interface EJB and its implementation class (session bean). I'm Using Netbeans 8 and Glassfish 4.0. After succesfully building the app I get the following stack when trying to run it:

SEVERE:   Exception during lifecycle processing
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Lcom/manaar/security/services/remote/UserServiceRemote;
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:168)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352)
...

SEVERE:   Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Lcom/manaar/security/services/remote/UserServiceRemote;

The steps I'm following are:

1) Create the Java class library and populate it with the remote interface and entity class 2) Create the EJB module and populate this with the implementation class (session bean) and dao methods 3) Add both projects above to the library of the client JSF web application 4) Call the remote interface as an EJB in the client app and use the methods to show a user profile

The main classes are: 1) Java class library

@Remote
public interface UserServiceRemote {
public List<Users> findAllUsers();
public Users findByName(String userName);
public void createUser(Users newUser);
public void updateUser(Users updatedUsers);
public void deleteUser(Users userToDelete);
public void adminUpdateUser(Users aUpdatedUser);


@Entity
@Table(name = "SHA_USERS")
public class Users {

   @Id
private String userName;
private String password;

2) EJB Module

@Stateless
public class UserServiceImpl implements UserServiceRemote {

 @EJB
private UsersDao dao;

@Override
public Users findByName(String userName) {
    return dao.findByName(userName);
}

3) Java class library and EJB module are both added as Projects in the client application

4) The managed bean in the client app:

@ManagedBean
@SessionScoped
public class SecClientFull {

@EJB
private UserServiceRemote useServ;

private Users loggedUser;
private String userName;

public String showProfile() {
    loggedUser = useServ.findByName(userName);
    return "/Users/AppUserProfile";

}

public String getUserName() {
    userName = FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
    return userName;
}
...
}

Looking in this forum and elsewhere online I've seen several posts talking about bug in GF3. I'm using the newest version so I'm hoping this is not a bug and I have simply configured this wrong.

Also I'm not clear if I still need to add any configurations for the EJBs in the glassfish-web.xml (or sun-web.xml) configuration file. I've assumed that the Java EE annotations are sufficient.

Finally I should say I coded this manually. I'm not sure if using the Netbeans wizards to create the libraries and session beans is a better way to make sure the configurations are correct.

Would really appreciate any advice or feedback and pls let me know if I need to provide further information. Thanks in advance!

The solution to the above is twofold:

1) Make sure that both Java class library and EJB module are created with separate 'lib' directories if they are to used by stand alone applications (which they are in my case). It's easy to overlook that point if you're creating EJBs for use in the same app (as many tutorials are)

2) The entity class (Users) must implement the java.io.Serialization interface and so should the managed bean on the client side

When first re-creating the Java class library and EJB module I got a ClassCastException that Users cannot be cast to Serialization. As the Java EE tutorial says the implementation of Serialization is for security reasons when EJB modules are used by stand alone applications and transferred accross networks.

So I added the interface to the entity class and the managed bean on the client side. The exception was eliminated and the app now runs perfectly. Thanks again!

Did you create default no args constructor for your class. Because I don't see it in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM