EJB stateless bean can only return value, cannot print

476 views Asked by At

I try to implement a remote stateless bean. For the methods in this bean, the return values can be correctly returned. However, for "println" in these methods cannot print any thing to the console. The interface is

public interface HelloWorld {
    public void SayHelloWorld(String name); 
    public String SayHello(String name);
}

The implementation is

@Stateless
@Remote(HelloWorld.class)
public class HelloWorldBean implements HelloWorld {

    @Override
    public void SayHelloWorld(String name) {
        System.out.println(name + " say hello to the world!");
    }

    @Override
    public String SayHello(String nameString) {
        System.out.println("This is SayHello()");
        return nameString;
    }

}

The client is

public class HelloWorldTest {

    public static void main(String[] args) {

        try {
            FileInputStream inputStream = new FileInputStream("ejb.properties");
            Properties pro = new Properties();
            pro.load(inputStream);
            InitialContext icContext = new InitialContext(pro);
            HelloWorld hw = (HelloWorld) icContext.lookup("ejb/HelloWorldBean!com.ejbinterface.HelloWorld");
            hw.SayHelloWorld("tom");
            String aa = hw.SayHello("tom");
            System.out.println(aa);
        } catch (NamingException e) {
        e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

I do not know why the println in method "SayHelloWorld" and "SayHello" is not executed. However, the variable "aa"(in client) correctly get the return value.

1

There are 1 answers

2
fdreger On BEST ANSWER

It prints to the console of the server (or, if redirected, to some log file - but this is merely a configuration issue). Just look for the output, if the methods get executed, then the output is there.