2
votes

I've created very basic EJB3 stateful bean but can't access it remotely. I'm getting:

Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfacecom.s9120.ejb.Calculator [Root exception is java.lang.ClassNotFoundException: com.s9120.ejb.Calculator]

I have 1 bean and 1 interface. It looks like the interface is not deployed (I'm using GlassFish): Here is the code:

package com.calc.ejb;

import javax.ejb.Remote;

@Remote
public interface Calculator {

    public Double multiply(Double multiplier, Double multiplicand);
    public Double divide(Double dividend, Double divisor);
    public Double add(Double addend, Double augend);
    public Double subtract(Double minuend, Double subtrahend);

    public void saveToMemory(Double number);
    public Double retrieveFromMemory();
}

Bean:

package com.calc.ejb;

import javax.ejb.Remote;
import javax.ejb.Stateful;

/**
 * Session Bean implementation class CalculatorBean
 */
@Stateful
@Remote(Calculator.class)
public class CalculatorBean implements Calculator{
/* Implementation */
}

Accessing it:

context = new InitialContext(); 
Calculator calculator = (Calculator) context.lookup("java:global/Zad3_s9120/CalculatorBean");

Do I have to do some steps to make interface available to session bean? I'm adding it from Eclipse with "Add and Remove" server menu.

1

1 Answers

6
votes

From what I can see, you have different packages.

You've defined interface as:

com.calc.ejb.Calculator 

but your exception tells you about:

com.s9120.ejb.Calculator

Perhaps you don't have appropriate class in your client project?

BTW: You don't need to specify @Remote on both - the interface and EJB. You can do only @Remote(MyClass.class) on EJB or @Remote on interface.