简体   繁体   中英

Scala EJB without interface doesn't seem to work

I'm attempting to deploy an EJB written in Scala to an app server.

If I create a stateless session bean and give it a (remote) interface, then it works fine (the interface is a trait).

The problem is when I want to create a stateless session bean with NO interface. On both Glassfish and JBoss I get an error. If I convert the code to Java, then I have no problem.

Glassfish 3.1.1: IllegalArgumentException: Can not set ejb.MyScalaEJB2Bean field ch.maxant.produkte.web.scala.BhfSuche2.scalaEjb2NoInterface to $Proxy290

JBoss 7.0.2.Final: IllegalArgumentException: Can not set ejb.MyScalaEJB2Bean field ch.maxant.produkte.web.scala.BhfSuche2.scalaEjb2NoInterface to scala.ScalaObject$$$view4

The EJB source is:

package ch.maxant.produkte.ejb.scala

@Stateless(name = "ScalaTestBean2", mappedName = "ScalaTestBean2")
class MyScalaEJB2Bean {

  def doStuff(x: String): String = {
    "hello " + x + ", this is a scala EJB"
  }

}

The Servlet which needs the EJB injecting has this source:

package ch.maxant.produkte.web.scala;

@WebServlet(urlPatterns = Array("/BhfSuche2"))
@SerialVersionUID(1L)
class BhfSuche2 extends HttpServlet {

  @EJB(lookup="java:global/ProdukteEAR/ProdukteScala/ScalaTestBean2")
  var scalaEjb2NoInterface: MyScalaEJB2Bean = null

  @throws(classOf[ServletException])
  @throws(classOf[IOException])
  override def doGet(request: HttpServletRequest, response: HttpServletResponse):Unit = {

    val msg2 = scalaEjb2NoInterface.doStuff("ScalaWebServlet")
    response.getWriter.write(msg2 + "\r")
  }
}

Why am I getting these errors and is there anything I can do about it?

Cheers,
Ant

Fixed.

Add @LocalBean to the bean impl, just after @Stateless .

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