开发者

How to use the @WebInitParam that's nested in the @WebServlet annotation in Scala?

I'm playing around with Scala and servlets and I'm trying to use the JEE6 annotations to configure servlets written in Scala. I'm running into a issue with nested annotations. The java code would look something like:

@WebServlet(name = "ExampleServlet", urlPatterns = {"/example"},
initParams = {@WebInitParam(name="param1", value="value1"), 
              @WebInitParam(name="param2", value="value2")}
)
public class ExampleServlet extends HttpServlet {

}

the scala code I'm trying is like:

@WebServlet(name = "ExampleServlet", urlPatterns = Array("/example"), 
initParams = Array(@WebInitParam(name="param1", value="value1", 
                   @WebInitParam(name="param2", value="value2")))
class ExampleServlet extends HttpServl开发者_开发问答et {

}

but when I try to compile it I get the following:

[ERROR] /Users/brian/workspace/dsg-scalatra/src/main/scala/org/mbari/dsg/RotatorServlet.scala:15: error: illegal start of simple expression

[INFO] initParams = Array( @WebInitParam(name="imageDirectory", value="/assets/images/rotator")) )

with the error pointing to the @WebInitParam annotation.

Any suggestions on how to use the @WebInitParam that's nested in the @WebServlet annotation in Scala?


You have to use the new keyword to instantiate any annotations inside of another annotation:

@WebServlet(name = "ExampleServlet", urlPatterns = Array("/example"), 
            initParams = Array(new WebInitParam(name="param1", value="value1"), 
                               new WebInitParam(name="param2", value="value2")))
class ExampleServlet extends HttpServlet {

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜