在wildfly回报休息“未找到”,但JSP的作品,有什么不对?

问题描述 投票:0回答:1

我开始学习休息和我尝试做REST返回Aluno,当我将测试的“邮差”或一个JSON“火狐”我收到此404错误,但疗法是不访问JSP没有问题。

我尝试了很多想,我改变了的休息,容易,休眠,尝试做另一种休息,但只有相同的答案版本。

技术应用于:wildfly,RestEasy的,EasyCriteria,JPA,休眠。

网址:http://localhost:8080/teachmanager/ws/aluno

怎么了?!

回答:

<html>
    <head>
        <title>Error</title>
    </head>
    <body>Not Found</body>
</html>

休息:

@Path("aluno")
public class AlunoRest {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String busca() {
        Dao<Aluno> dao = new Dao<Aluno>(JPAUtil.getEntityManager(), Aluno.class);
        Aluno aluno = dao.getById(1);
        return aluno.toJson();
    }

}

pom.hml:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.com.ilearning.teachmanager</groupId>
  <artifactId>teachmanager</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>


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

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.7.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>5.2.13.Final</version>
    </dependency>

    <dependency>
       <groupId>dom4j</groupId>
       <artifactId>dom4j</artifactId>
       <version>1.6.1</version>
       <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>uaihebert.com</groupId>
        <artifactId>EasyCriteria</artifactId>
        <version>3.0.0</version>
    </dependency>

    <!-- <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.4.6.Final</version>
    </dependency> -->

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.2</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.2.1.GA</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>2.2.0.GA</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-servlet-initializer</artifactId>
        <version>3.5.0.Final</version>
    </dependency>

  </dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

veb.hml:

    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <context-param>
        <param-name>resteasy.scan</param-name> 
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/ws</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>restEasy</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>restEasy</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>
rest java-ee jax-rs wildfly resteasy
1个回答
0
投票

我改变Web模块版本3.0和多数民众的作品!但我不明白为什么不上3.1工作!

我发现一个新的方式来做到这一点的web服务,不使用的web.xml。

我创建一个配置类:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("service")
public class RestManager extends Application{

}

并创建一个正常的休息类:

@Path("teste")
public class Teste {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String getTeste() {
        return "teste";
    }


    @GET
    @Path("lista")
    @Produces(MediaType.APPLICATION_JSON)
    public String lista() {
        String ret = "";
        try {
            Dao<Aluno> dao = new Dao<Aluno>(JPAUtil.getEntityManager(), Aluno.class);
            List<Aluno> lista = dao.getAll();
            ret = new Gson().toJson(lista);
        } catch (Exception e) {
            ret = new Gson().toJson(e.getMessage());
        }

        return ret;
    }



}
© www.soinside.com 2019 - 2024. All rights reserved.