Jersey REST ResourceConfig实例不包含任何根资源类[重复]

如何解决Jersey REST ResourceConfig实例不包含任何根资源类[重复]

||                                                                                                                   这个问题已经在这里有了答案:                                                      

解决方法

我有相同的错误消息,并通过修改我的web.xml文件来解决。确保其中包含以下内容:
<init-param>
   <param-name>com.sun.jersey.config.property.packages</param-name>
   <param-value>your.package.name.here</param-value>
</init-param>
    ,我发现泽西岛可能找不到根资源的另一个原因。错误消息是相同的,因此我认为这是在这里记录根本原因的一个很好的理由,以防其他人迷失它。 我有一个根资源类,上面有以下注释:
@Singleton
@Path(\"/helloWorld\")
@Service(...) // my own custom annotation
public class MyRootResource {
...
}
这将导致Jersey内的根资源扫描失败。 解决方法是更改​​批注的顺序:
@Service(...) // my own custom annotation
@Singleton
@Path(\"/helloWorld\")
public class MyRootResource {
...
}
这可行。     ,首先,请注意,在类上使用@GET不足以将其标识为根资源类。该类上必须有一个@Path。您可以,所以这不是问题。 我遇到了与您相同的问题:它在Eclipse中有效,但是在构建供外部使用时却不起作用。 我使用的是嵌入式Jetty,其main()如下所示:
public static void main(String argv[])
{
    try
    {
        // from http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty
        Server server = new Server(8080);
        ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextHandler.setContextPath(\"/\");
        server.setHandler(contextHandler);

        // http://stackoverflow.com/questions/9670363/how-do-i-programmatically-configure-jersey-to-use-jackson-for-json-deserializa
        final PackagesResourceConfig prc = new PackagesResourceConfig(\"com.ultimatefoodfight.server.api\");
        final Map<String,Object> prcProperties = prc.getProperties();
        prcProperties.put(JSONConfiguration.FEATURE_POJO_MAPPING,true);

        // from http://stackoverflow.com/questions/7421574/embedded-jetty-with-jersey-or-resteasy
        contextHandler.addServlet(new ServletHolder(new ServletContainer(prc)),\"/*\");

        server.start();
        server.join();
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}
(在嵌入Jetty时,它代替了web.xml。)com.sun.jersey.api.core.PackagesResourceConfig扫描命名的类以查找根资源提供程序类-我确定web.xml只是指向在同一时间。这在Eclipse中运行良好。服务器启动会在控制台中正确报告此情况:
INFO: Scanning for root resource and provider classes in the packages:
  com.ultimatefoodfight.server.api
Jul 29,2012 7:31:28 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class com.ultimatefoodfight.server.api.Users
  class com.ultimatefoodfight.server.api.Contests
但是,当我在服务器上启动应用程序时,我只得到其中的前两行,并且没有找到Root资源类。 事实证明,当您制作一个罐子时,罐子的构造有不同的选择。特别是,如果仅通过列出类的路径来做到这一点,就会得到 只是那些条目。但是,如果您使用通配符将jar指向目录,则还将获得所有中间路径。请参阅以下消息,了解为我提供提示的示例:https://groups.google.com/d/msg/neo4j/0dNqGXvEbNg/xaNlRiU1cHMJ。 PackagesResourceConfig类依赖于具有包含软件包名称的目录,以便在其中查找这些类。我回到Eclipse,并在\“导出...> Jar \”对话框的底部找到一个用于\“添加目录项。\”的选项。我将其打开,再次导出jar,然后进行扫描我的资源类。您需要在构建环境中找到一些可比较的选项。     ,我也花了5到6个小时努力解决这个问题,终于解决了这个问题。这也许也对您有用。 我一直在使用的源代码可在Lars Vogel的教程页面上找到。使用Apache Tomcat 6.0.20,asm-all-3.3.1.jar,jersey-bundle-1.17.1.jar和jsr311-api-1.1.1.jar,我得到的结果与OP相同,即
INFO: Root resource classes found:
  class com.mypackage.MyClass
13/03/2013 4:32:30 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
我在各个部署文件中具有以下设置:
context root = rivets
<url-pattern>/rest</url-pattern>
@Path(\"/hello\")
尝试使用以下URL访问资源给出了404错误
 http://localhost:8080/rivets/rest/hello
我最终可以通过将url-pattern更改为来解决此问题:
<url-pattern>/rest/*</url-pattern>
尽管我不确定在开始引入更复杂的资源时会如何坚持。无论如何,希望这可以对某人有所帮助。     ,我发现“找不到提供程序类”消息很可怕,但并不重要。 \“ ResourceConfig实例不包含任何根资源类\”是一个更大的问题。 我发现资源类需要用@Path注释,并且提供程序类(如果有的话-我们使用一种将异常映射到HTTP响应代码)需要用@Provider注释,并且两者都必须在正确的包裹,然后泽西岛会找到他们。     ,您可能需要使用这样的网址
http://localhost:8080/<web_context_root>/nd/hello
    ,所以我仔细阅读了答案,仍然遇到了同样的问题。我解决如下。 将\“ jetty-web.xml \”添加到\“ WEB-INF \”文件夹。从而: src / main / webapp / WEB-INF / jetty-web.xml jetty-web.xml的内容为:
<?xml version=\"1.0\"  encoding=\"ISO-8859-1\"?>
<!DOCTYPE Configure PUBLIC \"-\" \"http://www.eclipse.org/jetty/configure.dtd\">
<Configure class=\"org.eclipse.jetty.webapp.WebAppContext\">
    <Set name=\"contextPath\">/YourEndpoint</Set>
</Configure>
我的休息时间现在可以在:
http://localhost:8080/YourEndpoint/webresources/someMethod
希望这可以帮助某人。     ,我有同样的问题。通过在web.xml中固定init-param标记下的param-value来解决该问题。 默认情况下,Eclipse在web.xml中将项目名称设置为display-name。那不应该复制到param-value,而是Java包。
  <init-param>
    <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.test.demo</param-value>
    </init-param> 
希望这可以帮助。     ,若要解决此问题,请验证您的类MapperIn,需要指定Path:
import javax.ws.rs.GET;
import javax.ws.rs.OPTIONS;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.lot.account.api.doc.GetMemberAccountsIn;
import com.lot.common.doc.CommonApi;
import com.lot.common.doc.FlowData;
import com.lot.security.authorization.RequestData;


@Path(\"/account/member/\")
public class MapperIn {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path(\"/{memberId}\")
    public GetAccountIn prepareGetAccount(@PathParam(\"memberId\") String memberId) {

        // create apiInput
        GetAccountIn apiInput = new GetAccountIn ();

        // map values from url
            apiInput.setMemberId(memberId);


        return apiInput;
    }
//...
}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-