最近我从使用 RESTEasy 2.3.6.Final 更新到最新版本,结果发现 org.jboss.resteasy.spi.NotFoundException 和 org.jboss.resteasy.spi.UnauthorizedException 已被弃用。这些有替代品吗?
4 回答
NotFoundException 已被拉到上游:JAX-RS API 本身现在包含它:http ://docs.oracle.com/javaee/7/api/javax/ws/rs/NotFoundException.html
RESTeasy 3.0.4 Javadocs 简要提到了这一点:“JAX-RS 现在有这个异常” http://docs.jboss.org/resteasy/docs/3.0.4.Final/javadocs/org/jboss/resteasy/spi/NotFoundException。 html
检查RESTEasy 源代码,您可以看到UnauthorizedException
该类不包含任何有关弃用替换的文档,但它包含以下注释:
Thrown by RESTEasy when HTTP Unauthorized (401) is encountered
在源代码根文件夹中运行以下命令将让您找到任何类似的文档类:
find . -name "*.java" -type f -exec grep "when HTTP Unauthorized (401)" {} \; -print
它返回:
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/UnauthorizedException.java
./security/resteasy-crypto/src/main/java/org/jboss/resteasy/security/doseta/UnauthorizedSignatureException.java
检查第二个文件的标题(./security/resteasy-crypto/src/main/java/org/jboss/resteasy/security/doseta/UnauthorizedSignatureException.java
),您可以看到:
/**
* Thrown by RESTEasy when HTTP Unauthorized (401) is encountered
*/
public class UnauthorizedSignatureException extends ReaderException
{
...
因此,根据声明的相似性,org.jboss.resteasy.security.doseta.UnauthorizedSignatureException
看起来像是替换的最佳候选者。org.jboss.resteasy.spi.UnauthorizedException
对 应用类似的方法NotFoundException
没有返回任何结果,搜索具有相似名称的文件(包含NotFound
作为文件名的一部分):
$ find . -name "NotFound*" -type f
回来:
./examples/oreilly-workbook-as7/ex07_1/src/main/java/com/restfully/shop/services/NotFoundExceptionMapper.java
./examples/oreilly-workbook-as7/ex07_1/src/main/java/com/restfully/shop/services/NotFoundException.java
./examples/oreilly-workbook/ex07_1/src/main/java/com/restfully/shop/services/NotFoundExceptionMapper.java
./examples/oreilly-workbook/ex07_1/src/main/java/com/restfully/shop/services/NotFoundException.java
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/NotFoundException.java
./jaxrs-api/src/main/java/javax/ws/rs/NotFoundException.java
./resteasy-links/src/main/java/org/jboss/resteasy/links/impl/NotFoundException.java
检查班级./jaxrs-api/src/main/java/javax/ws/rs/NotFoundException.java
:
/**
* A runtime exception indicating a resource requested by a client was
* {@link javax.ws.rs.core.Response.Status#NOT_FOUND not found} on the server.
*
* @author Sergey Beryozkin
* @author Marek Potociar
* @since 2.0
*/
public class NotFoundException extends ClientErrorException {
...
标题注释指出该类基本上与已弃用的类一样工作,因此 javax.ws.rs.NotFoundException
看起来像是类的替代品(可能是替代品)org.jboss.resteasy.spi.NotFoundException
。希望这会有所帮助。
这是一个运行时异常,表示在服务器上未找到客户端请求的资源。将以下条目添加到您的 web.xml 中。这适用于最新的 RESTEasy。
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.org.abc.xyz.MainClassName</param-value>
</context-param>
您可以指定要注册的 JAX-RS 资源类名称的完全限定名称。如果您有多个类条目,请使用逗号分隔符。
这是已弃用的异常列表及其替换列表。文档链接是https://docs.jboss.org/resteasy/docs/3.0.13.Final/javadocs/deprecated-list.html#exception