WildFly 12和Java 10不识别注释 我所拥有的 Tomcat 9.0.7 WildFly 12.0.0 JDK 10 Maven 3.5.3 相关文件

WildFly 12和Java 10不识别注释 我所拥有的 Tomcat 9.0.7 WildFly 12.0.0 JDK 10 Maven 3.5.3 相关文件,java,tomcat,servlets,wildfly,Java,Tomcat,Servlets,Wildfly,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</

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>com.example.training</groupId>
  <artifactId>BigVoiceWebApp</artifactId>
  <name>BigVoiceWebApp Maven Webapp</name>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <url>http://maven.apache.org</url>
    <properties>
        <maven.compiler.source>1.10</maven.compiler.source>
        <maven.compiler.target>1.10</maven.compiler.target>
    </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.2</version>
      <scope>provided</scope>
    </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
<!--  <build>
    <finalName>${project.artifactId}</finalName>
  </build>-->
<profiles>
  <profile>
    <id>release-profile</id>
    <build>

      <plugins>
        <plugin>
          <groupId>org.wildfly.plugins</groupId>
          <artifactId>wildfly-maven-plugin</artifactId>
        </plugin>

      </plugins>
    </build>
  </profile>
</profiles>
  <build>
    <finalName>BigVoiceWebApp</finalName>
  </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/PostgresDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>
我的问题 我有这样的servlet:

@WebServlet(name = "MemberController", urlPatterns = {"/MemberController"})
@MultipartConfig
public class MemberController extends HttpServlet {
现在的问题是,WildFly不知何故不遵守注释。当我访问URL时,这是我在浏览器中得到的内容(通过查看源HTML复制):

当我将完全相同的WAR文件重新加载到Tomcat时,注释被正确读取


我的问题是,为什么?以及如何让WildFly识别这些注释?

感谢您提供的文件。是Java10。在构建过程中,我注意到:

[INFO] --- maven-war-plugin:2.2:war (default-war) @ SampleForError ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/scott/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Wildfly启动时会发出类似的警告。Wildfly 12和Java 10的某些组合在JEE7模式下无法正常工作

但是,有多种变通方法。如果你运行Wildfly,它就会工作。通过运行
bin/standalone.sh-Dee8.preview.mode=true
bin/standalone.sh-c standalone-ee8.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>com.example.training</groupId>
  <artifactId>BigVoiceWebApp</artifactId>
  <name>BigVoiceWebApp Maven Webapp</name>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <url>http://maven.apache.org</url>
    <properties>
        <maven.compiler.source>1.10</maven.compiler.source>
        <maven.compiler.target>1.10</maven.compiler.target>
    </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.2</version>
      <scope>provided</scope>
    </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
<!--  <build>
    <finalName>${project.artifactId}</finalName>
  </build>-->
<profiles>
  <profile>
    <id>release-profile</id>
    <build>

      <plugins>
        <plugin>
          <groupId>org.wildfly.plugins</groupId>
          <artifactId>wildfly-maven-plugin</artifactId>
        </plugin>

      </plugins>
    </build>
  </profile>
</profiles>
  <build>
    <finalName>BigVoiceWebApp</finalName>
  </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/PostgresDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>
否则,在Java8中不会有任何更改

顺便说一句,您正在努力混淆正在运行的任何容器。在
pom.xml
中指定servlet spec 4,但是web.xml是:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

谢谢你的文件。是Java10。在构建过程中,我注意到:

[INFO] --- maven-war-plugin:2.2:war (default-war) @ SampleForError ---
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/scott/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Wildfly启动时会发出类似的警告。Wildfly 12和Java 10的某些组合在JEE7模式下无法正常工作

但是,有多种变通方法。如果你运行Wildfly,它就会工作。通过运行
bin/standalone.sh-Dee8.preview.mode=true
bin/standalone.sh-c standalone-ee8.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>com.example.training</groupId>
  <artifactId>BigVoiceWebApp</artifactId>
  <name>BigVoiceWebApp Maven Webapp</name>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <url>http://maven.apache.org</url>
    <properties>
        <maven.compiler.source>1.10</maven.compiler.source>
        <maven.compiler.target>1.10</maven.compiler.target>
    </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.2.2</version>
      <scope>provided</scope>
    </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
<!--  <build>
    <finalName>${project.artifactId}</finalName>
  </build>-->
<profiles>
  <profile>
    <id>release-profile</id>
    <build>

      <plugins>
        <plugin>
          <groupId>org.wildfly.plugins</groupId>
          <artifactId>wildfly-maven-plugin</artifactId>
        </plugin>

      </plugins>
    </build>
  </profile>
</profiles>
  <build>
    <finalName>BigVoiceWebApp</finalName>
  </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/PostgresDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>
否则,在Java8中不会有任何更改

顺便说一句,您正在努力混淆正在运行的任何容器。在
pom.xml
中指定servlet spec 4,但是web.xml是:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

除了使用Java1.8,我无法用所有相同的方法重现您的问题。Wildfly 12,Servlet规范4.0(无论是否在
web.xml
中有合适的版本规范)。您是否尝试过删除一些其他依赖项以获得一个小的可复制测试用例?我已经包含了一个在我的设置中不起作用的示例项目。这个在我的WildFly中肯定不起作用。你可以试着把它上传到你的网站上看看吗?除了我使用的是Java 1.8,我无法用同样的方式重现你的问题。Wildfly 12,Servlet规范4.0(无论是否在
web.xml
中有合适的版本规范)。您是否尝试过删除一些其他依赖项以获得一个小的可复制测试用例?我已经包含了一个在我的设置中不起作用的示例项目。这个在我的WildFly中肯定不起作用。你可以试着把它上传到你的网站上看看吗?我需要java 9和更高版本,因为java 8中没有某些功能。我将注意到未来WildFly部署的“Java8”需求。同时,该web.xml实际上是从maven webapp原型生成的。我忘了把它取下来。还有一件事一旦我摆弄了这些文件(将分支更改为另一个版本,工作,返回到第一个分支,执行
mvn clean package
并上传WAR),这再次不起作用。注释有时有效,有时无效。我无法始终如一地重现这些问题,但它始终不起作用。我需要java 9及以上版本,因为java 8中没有某些功能。我将注意到未来WildFly部署的“Java8”需求。同时,该web.xml实际上是从maven webapp原型生成的。我忘了把它取下来。还有一件事一旦我摆弄了这些文件(将分支更改为另一个版本,工作,返回到第一个分支,执行
mvn clean package
并上传WAR),这再次不起作用。注释有时有效,有时无效。我无法始终如一地重现这些问题,但它始终不起作用。