I'm getting nervous not understanding how the ejb has to be called, since I'm getting errors with a simple example.
I have an EJB project called Test
. It has only two classes: HelloWorldBean , HelloWorldInterface
//HelloWorldBean
package com.demo;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Remote(HelloWorldInterface.class)
public class HelloWorldBean implements HelloWorldInterface {
public String helloWorld() {
return "Hello world !";
}
}
//HelloWorldInterface
package com.demo;
public interface HelloWorldInterface {
String helloWorld();
}
Both are packed in a WAR called Test.WAR
that has Test.jar inside, and it is deployed in the WAS 7.0 server.
I have another project called TestWeb
that will be packed and deployed in the same server. Here I implemented a controller of the mvc.
package controller;
import javax.ejb.EJB;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class My_Controller {
@EJB
private HelloWorldInterface helloBean;
@RequestMapping("testpage")
public ModelAndView mostraPagina(){
ModelAndView model = new ModelAndView();
model.setViewName("testpage");
model.addObject("hello", "? " + "EJB:" + helloBean.helloWorld());
return model;
}
}
I'm getting the errors in the following lines:
Edit: The error is:
HelloWorldInterface cannot be resolved to a type. Location: My_Controller.java
I created from the beginning a new ejb project and I chose to generate his client. After that, I create a session bean with the remote interface and I used the RAD option "expose the RPC adapter service" with the Web project. In this way I have two EARs both with two jars (including the client).
Roughly speaking:
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.