部署EAR时出现此错误:
引起: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406:找不到类型为interface的EJB ' it.ejb32.ConverterBean'用于绑定 it.webtest.SessionBeanTest / converterBean"},
这里有一些代码:
接口
package it.ejb32;
public interface Converter {
float celsiusToFahrenheit(float temperature);
float fahrenheitToCelsius(float temperature);
}
ConvertBean
package it.ejb32;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Stateless
@Local
public class ConverterBean implements Converter {
public ConverterBean() {}
@Override
public float celsiusToFahrenheit(float temperature) {
return temperature * 1.8f + 32;
}
@Override
public float fahrenheitToCelsius(float temperature) {
return (temperature - 32) / 1.8f;
}
}
的Servlet
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import it.ejb32.ConverterBean;
@WebServlet("/SessionBeanTest")
public class SessionBeanTest extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB
private ConverterBean converterBean;
public SessionBeanTest() {}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Conversion test:"+ converterBean.celsiusToFahrenheit(Float.parseFloat(request.getParameter("p"))));
}
}
我是否需要使用 @Inject 接口而不是bean?
谢谢