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?