2013-03-28 45 views
0

我一個JSF 2.0 Web應用程序中的Tomcat 7.0.29運行,並試圖使用servlet 3.0 註釋但我不能看到日誌的servlet沒有工作寫在它的init()方法中。的Servlet 3.0不應用啓動時加載

我讀過了同樣的問題,很多答案,但依然沒有seccessful。

這是我的文件怎麼看:

的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app metadata-complete="false" 
    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_3_0.xsd" 
    version="3.0"> 
    <display-name>GestionCongesFeki</display-name> 
    <welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
    </welcome-file-list> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.xhtml</url-pattern> 
    </servlet-mapping> 


<!-- <servlet> --> 
<!--  <servlet-name>AjaxRelaisServlet</servlet-name> --> 
<!--  <servlet-class>utils.AjaxRelaisServlet</servlet-class> --> 
<!--  <load-on-startup>2</load-on-startup> --> 
<!-- </servlet> --> 
<!-- <servlet-mapping> --> 
<!--  <servlet-name>AjaxRelaisServlet</servlet-name> --> 
<!--  <url-pattern>/AjaxRelaisServlet/*</url-pattern> --> 
<!-- </servlet-mapping> --> 

</web-app> 

pom.xml中

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>esprit.pfe2013</groupId> 
    <artifactId>GestionCongesFeki</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>GestionCongesFeki Maven Webapp</name> 
    <url>http://maven.apache.org</url> 

<repositories> 
     <repository> 
      <id>central</id> 
      <name>Maven Repository Switchboard</name> 
      <layout>default</layout> 
      <url>http://repo1.maven.org/maven2</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </repository>  
     <repository> 
      <id>prime-repo</id> 
      <name>Prime Repo</name> 
      <url>http://repository.primefaces.org</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>central</id> 
      <name>Maven Plugin Repository</name> 
      <url>http://repo1.maven.org/maven2</url> 
      <layout>default</layout> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <releases> 
       <updatePolicy>never</updatePolicy> 
      </releases> 
     </pluginRepository> 
    </pluginRepositories> 

<!-- <repositories> --> 
<!-- <repository> --> 
<!--   <id>central</id> --> 
<!--   <name>Central Repository</name> --> 
<!--   <url>http://repo.maven.apache.org/maven2</url> --> 
<!--   <layout>default</layout> --> 
<!--   <snapshots> --> 
<!--    <enabled>false</enabled> --> 
<!--   </snapshots> --> 
<!--  </repository> --> 


<!-- </repositories> --> 

    <dependencies> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>3.0.1</version>   
     </dependency> 



     <!-- PrimeFaces --> 
     <dependency> 
      <groupId>org.primefaces</groupId> 
      <artifactId>primefaces</artifactId> 
      <version>3.4.1</version> 
     </dependency> 


     <!-- JSF 2 --> 
     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-api</artifactId> 
      <version>2.1.11</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-impl</artifactId> 
      <version>2.1.11</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>taglibs</groupId> 
      <artifactId>standard</artifactId> 
      <version>1.1.2</version> 
     </dependency> 




     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.13</version> 
     </dependency> 


     <dependency> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>2.4.3</version> 
</dependency> 






    </dependencies> 
    <build> 
    <finalName>GestionCongesFeki</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

並且servlet:

package utils; 

import java.io.IOException; 

import javax.servlet.Servlet; 
import javax.servlet.ServletConfig; 
import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

/** 
* Servlet implementation class AjaxRelaisServlet 
*/ 
@WebServlet("/AjaxRelaisServlet") 
public class AjaxRelaisServlet extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    /** 
    * @see HttpServlet#HttpServlet() 
    */ 
    public AjaxRelaisServlet() { 
     super(); 
     // TODO Auto-generated constructor stub 
    } 

    /** 
    * @see Servlet#init(ServletConfig) 
    */ 
    public void init(ServletConfig config) throws ServletException { 
     System.out.println("This is AjaxRelaisServlet initialisaton !!!"); 
    } 

    /** 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
    } 

    /** 
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
    } 

} 

其實當我d時servlet工作正常在web.xml(註釋代碼)中將它擦掉,但是當我使用註釋時不會。 順便說一句,我想知道如果我能擺脫此問題時將得到解決web.xml中的,但我不知道怎麼JSF servlet將沒有它被宣佈。

感謝您的幫助!

+0

你在哪裏BalusC!我知道你是這方面的專家! :) – Bardelman

+1

他聽不到你。 Muahahahahahhahahahhahah>:d – kolossus

+0

倒帶太高興了這個安都笑,而不是試圖幫助我:d – Bardelman

回答

6

loadOnStartup=1屬性添加到您的@WebServlet註釋中,以使servlet在應用程序啓動時加載。此屬性類似於你在web.xml中找到<load-on-startup/>元素。

@WebServlet(name="AjaxRelaisServlet",loadOnStartup=1,urlPatterns={"/AjaxRelaisServlet"}) 

當你有一把錘子,所有問題看起來都像釘子。

上的更換的web.xml完全的問題,您應該知道,有一些東西是註釋基於模型目前還無法實現。例如,僅使用註釋(AFAIK)無法實現過濾器排序。另外,你應該認識到一個具體的配置文件是自我記錄的。您的系統維護人員可以在web.xml中查看一下,並配置明智地瞭解應用中發生了什麼。與只有註釋的體系結構進行對比。要弄清楚系統中所有部分的連線是很困難的。

相關問題