0

When I bing Servlet to url using web.xml like it's shown below everyting works fine.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
    <servlet-name>MainServlet</servlet-name>
    <servlet-class>lv.rtu.sux.laip.web.MainServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MainServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
</servlet-mapping>

But when I'm trying to do this using @annotation @WebServlet I receive this message: The requested resource is not available using.

I've tried two variants:

@WebServlet(name="hello",urlPatterns={"/hello"})
public class MainServlet extends HttpServlet{

@WebServlet("/hello")
public class MainServlet extends HttpServlet{

UPDATE I've tried to run this app using normal Tomcat (before this I was using Embedded Tomcat) and now it works fine. But how can I normally run it with Embedded Tomcat? I am using libraries from maven group org.apache.tomcat.embed:

    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    tomcat.setPort(8089);
    Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    tomcat.start();
    tomcat.getServer().await();

Do I have to do some additional actions to make this app work with annotations?

Toro Boro
  • 377
  • 5
  • 16
  • And did you remove the web.xml file from the deployed application? Because it declares that the app version is 2.5, and this version doesn't support annotations. – JB Nizet Mar 26 '15 at 12:25
  • Yes, I removed the web.xml – Toro Boro Mar 26 '15 at 12:30
  • I found the soultion. It's described here: http://stackoverflow.com/questions/11669507/embedded-tomcat-7-servlet-3-0-annotations-not-working – Toro Boro Mar 26 '15 at 13:20

0 Answers0