首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >没有为公共javax.ws.rs.core.Response -泽西- MultiPartFeature类型的参数找到注入源。

没有为公共javax.ws.rs.core.Response -泽西- MultiPartFeature类型的参数找到注入源。
EN

Stack Overflow用户
提问于 2016-02-09 17:47:53
回答 1查看 10.2K关注 0票数 2

我正在创建一个没有web.xml文件的泽西和Jetty嵌入的web服务。它非常简单,它从HTML表单中通过POST接收二进制文件。我似乎没有正确地注册MultiPart特性,因为当我尝试将它与HTML一起使用时,我得到了以下错误:

*

警告:没有为类型为public javax.ws.rs.core.Response的参数找到注入源,org.multipart.demo.ReceiveFile.postMsg(java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition)会在索引0处抛出java.lang.Exception。2016-02-09 21:49:59.916:警告:/: for 1364335809-16:应用程序资源模型的不可用org.glassfish.jersey.server.model.ModelValidationException:验证在应用程序初始化过程中失败。来源=‘ResourceMethod{httpMethod=POST,消费型=多部分/表单-数据,producedTypes=text/平原,suspended=false,suspendTimeout=0,

  • 几个星期以来,我一直在寻找解决方案,我在StackOverflow上阅读了所有与此错误相关的问题,例如:

DATA: No injection source found for a parameter of type public javax.ws.rs.core.Response

Jersey 2 injection source for multipart formdata

他们没有帮助我,因为我不使用web.xml

我有三个类- ReceiveFile.class (尝试接收POST) - resourceConfig.class (尝试注册MultiPart特性)- JettyServer.class (创建服务器实例)

ReceiveFile.class

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package org.multipart.demo;
import java.io.InputStream;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;



@Path("/resources")
public class ReceiveFile 
{

        @POST
        @Path("/fileUpload")
        @Produces("text/plain")
        @Consumes(MediaType.MULTIPART_FORM_DATA)
        public Response postMsg (
                @FormDataParam("file") InputStream stream,
                @FormDataParam("file") FormDataContentDisposition fileDetail) throws Exception {


                    Response.Status respStatus = Response.Status.OK;




                    return Response.status(respStatus).build();
                    }

}

resourceConfig.class

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package org.multipart.demo;
import java.util.HashSet;
import java.util.Set;

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

import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;


    /**
     * Registers the components to be used by the JAX-RS application  
     *
     */
@ApplicationPath("/resources/fileUpload")
public class resourceConfig extends ResourceConfig {

     /**
        * Register JAX-RS application components.
        */  

        public resourceConfig(){
            register(ReceiveFile.class);    
            register(JettyServer.class);
            register(MultiPartFeature.class);
            //packages("org.glassfish.jersey.media", "com.mypackage.providers");


        }

}

JettyServer.class

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package org.multipart.demo;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.ServerProperties;


public class JettyServer
{
    //   private static final Logger LOGGER = Logger.getLogger(UploadFile.class.getName()); 


public static void main(String[] args) throws Exception
{

    ResourceConfig config = new ResourceConfig();
    config.packages("org.multipart.demo");

    Server jettyServer = new Server(8080);

    ResourceHandler resource_handler = new ResourceHandler();

    // Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of.
    // In this example it is the current directory but it can be configured to anything that the jvm has access to.
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{ "./index.html" , "./html/FileUpload.html"  });
    resource_handler.setResourceBase(".");

    //Jersey ServletContextHandler
    final ResourceConfig resourceConfig = new ResourceConfig(ReceiveFile.class);
    resourceConfig.register(MultiPartFeature.class);

    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    ServletHolder jerseyServlet = servletContextHandler.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/*" );
    jerseyServlet.setInitParameter(ServerProperties.PROVIDER_PACKAGES, "org.multipart.demo");

    // Add the ResourceHandler to the server.
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, servletContextHandler, new DefaultHandler() });
    jettyServer.setHandler(handlers);

    try {
        jettyServer.start();
        jettyServer.join();
    } finally {
        jettyServer.destroy();
    }
}


}

the pom.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<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>org</groupId>
  <artifactId>multipart.demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>multipart.demo</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  <dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-server</artifactId>
    <version>9.2.3.v20140905</version>
  </dependency>
  <dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-servlet</artifactId>
    <version>9.2.3.v20140905</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.7</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.7</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-jetty-http</artifactId>
    <version>2.7</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-moxy</artifactId>
    <version>2.7</version>
  </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
 <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.7</version>
</dependency>
 <dependency>
    <groupId>org.jvnet.mimepull</groupId>
    <artifactId>mimepull</artifactId>
    <version>1.9.6</version>
</dependency>
  </dependencies>
</project>

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-09 20:15:02

我在您的代码库中看到了三种不同的ResourceConfig,但它们都没有实际用于应用程序。因此,MultiPartFeature永远不会注册,这就是导致错误的原因。对于如何在您的情况下使用ResourceConfig,您有几个选项。

  1. 您可以实例化ServletContainer,传入ResourceConfig实例。不幸的是,没有ServletContextHolder#addServlet(Servlet)方法,但是有一个ServletContextHolder#addServlet(ServletHolder)方法,所以我们需要将ServletContainer封装在ServletHolder中。 servletContextHolder.addServlet(jerseyServlet,ServletHolder jerseyServlet =新ServletHolder(新ServletContainer(resourceConfig));
  2. 使用上面的选项,您可以使用本地实例或子类,但是如果您只有一个子类,比如您的第一段代码,那么您可以添加一个servlet来指定ResourceConfig子类。 新ServletContextHandler(ServletContextHandler.SESSIONS);ServletHolder jerseyServlet = servletContextHandler.addServlet(org.glassfish.jersey.servlet.ServletContainer.class,"/*“;jerseyServlet.setInitParameter(ServerProperties.PROVIDER_PACKAGES,"org.multipart.demo");jerseyServlet.setInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS,resourceConfig.class.getCanonicalName( ); 注意我设置应用程序类名的最后一个调用。
  3. 不使用ResourceConfig,您只需使用init param注册MulitPartFeature即可。 jerseyServlet.setInitParameter(ServerProperties.PROVIDER_CLASSNAMES,MultiPartFeature.class.getCanonicalName();
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35305517

复制
相关文章
C++ - “当前不会命中断点 还没有为该文档加载任何符号”解决方法
调试时总是出现“当前不会命中断点 还没有为该文档加载任何符号”这样的错误。出现这种情况的时候,可以按以下几种方式解决:
AIHGF
2019/02/18
8.7K0
\[vscode issue\] Golang Debug 无法命中断点
Kevinello
2023/10/18
5891
\[vscode issue\] Golang Debug 无法命中断点
VisualStudio 2019 调试项目使用 Portable PDB 提示不支持 PDB 格式
在新的 .NET 上,将会默认使用 Portable PDB 符号格式,而如果 VisualStudio 配置了使用托管兼容模式,那么将在加载符号的时候,将会提示不支持 PDB 格式
林德熙
2022/08/12
7800
Visual Studio 调试系列3 断点
断点是开发人员的工具箱中最重要的调试技术之一。 若要暂停调试程序执行所需的位置设置断点。 例如,你可能想要查看代码变量的状态或查看调用堆栈的某些断点。
张传宁IT讲堂
2019/09/17
5.4K0
Visual Studio 调试系列3 断点
解决VS2015无法调试问题
https://www.cnblogs.com/studyskill/p/7675402.html
用户7787521
2020/09/25
2.1K0
VS2013+python+boost.
    解压boost.python后,用VS的[本机命令提示工具](开始-VS2013-VS Tools)进入到boost的文件夹,运行bootstrap.bat生成bjam.exe。然后运行:
py3study
2020/01/03
7890
vs2013配置python
根据自己需求下载对应的版本:我下载的至最新的,直接点击黄色按钮下载,下载后文件:(python32位的)
py3study
2020/01/07
7920
VS 2013 打包程序教程
如果你只是想要在他人的机子上运行你的程序而不想安装,有一种简单的方法,只要使用本教程的“步骤—3.生成Release 文件夹”即可。但是有一点需要注意,如果你在程序中调用了其他的dll,那么你需要将这个dll 放置到Release文件夹。之后你只要将Release 文件夹拷贝到其他的机子上运行即可。
用户3148308
2019/02/25
1.2K0
VS 2013 打包程序教程
java文档注释符号_java的注释符号
标识符可以简单的理解成一个名字。 在Java中,我们需要给代码中的很多元素起名,包括类名、方法名、字段名、变量名等等。我们给对应元素起的名称就被称为标识符,一个正确的标识符需要遵循以下规则:
全栈程序员站长
2022/11/10
10.3K0
java文档注释符号_java的注释符号
卸载vs2013_如何卸载vs2015
最近編譯代碼時由於出現頭文件不匹配,需要升級VS2005,升級比較麻煩,乾脆直接過渡到VS2008得了. 先把.NET Framework從1.0一直刪除到3.0,再刪除一些相關依賴包時,安裝程式出錯.找了一下資料,正確的安裝過程如下:
全栈程序员站长
2022/11/09
6030
VS 2013安装教程「建议收藏」
大家好,又见面了,我是你们的朋友全栈君。 1.下载资源 此版本是旗舰版,其他版本自行下载 http://download.microsoft.com/download/9/3/E/93EA27FF
全栈程序员站长
2022/09/30
1.4K0
VS 2013安装教程「建议收藏」
vs2013下载及安装教程_VS2013下载
http://download.microsoft.com/download/0/7/5/0755898A-ED1B-4E11-BC04-6B9B7D82B1E4/VS2013_RTM_ULT_CHS.iso
全栈程序员站长
2022/10/03
5.2K0
vs2013下载及安装教程_VS2013下载
简单聊聊VisualStudio的断点调试
在debug过程中,我们有时需要查看程序在运行到某一行代码时,上下文中的变量或者一些其他的数据是什么样的,我们就要设置断点(Breakpoint)。断点顾名思义,就是运行到打断点的这一行,程序就中断,暂停。下面就看看如何使用VisualStudio来断点调试C#代码。
zls365
2021/04/23
1.1K0
简单聊聊VisualStudio的断点调试
vs2013注册_vs2008是什么软件
VS2008 注册方法:   VS2008注册方法非常简单,在开始>设置>控制面版>添加或删除程序>卸载vs.net2008(名字不太记得了)>出现卸载界面>点击Next>输入上面CD-key ->出现成功画面即可完美将试用版升级成为正式版。
全栈程序员站长
2022/09/23
7020
VS2013中Python学习笔记[基础入门]
        在上一节中简单的介绍了在VS2013中如何进行开发Hello World,在VS2013中进行搭建了环境。本节主要来简单的学习一下关于Python的基础。
aehyok
2018/08/31
5240
VS2013中Python学习笔记[基础入门]
迁移TFS,批量将文档导入SharePoint 2013 文档库
一、需求分析 公司需要将存在于旧系统(TFS)所有的文档迁移至新系统(SharePoint 2013)。现已经将50G以上的文档拷贝到SharePoint 2013 Server上。这些文档是一些
用户1161731
2018/01/11
1.5K0
迁移TFS,批量将文档导入SharePoint 2013 文档库
VS2013中Python学习笔记[环境搭建]
Python的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结构。
aehyok
2019/02/25
5970
C# 客户端程序 Visual Studio 远程调试方法
可以通过将msvsmon.exe复制到远程计算机,也可以通过安装远程工具来运行远程调试器(安装远程工具完成以后就和复制粘贴文件打开msvsmon.exe是一样的,多一个配置页面,这里主要演示复制粘贴):
郑子铭
2023/08/30
5560
C# 客户端程序 Visual Studio 远程调试方法
C# 客户端程序Visual Studio远程调试方法
传统桌面客户端的远程调试相比UWP,ASP等项目来说,配置比较麻烦,因为它是非部署的应用程序,原理是复制编译的文件到远程计算机,通过网络来连接和VS的通信,本文主要讲述WPF,WinForm应用程序的远程调试。
郑子铭
2023/08/30
5900
C# 客户端程序Visual Studio远程调试方法
IDA Pro Plugin wizard for vs2013
 感谢zadow提供的升级版的向导: https://forum.tuts4you.com/topic/34511-ida-pro-plugin-wizard-for-vs2013/
obaby
2023/02/23
4470

相似问题

当前不会命中断点。尚未为此文档加载任何符号

20

当前不会命中断点:尚未为此文档加载任何符号

170

当前不会命中断点。尚未为此文档加载任何符号。

50

问题:当前不会命中断点。尚未为此文档加载任何符号

12

无法调试-“当前不会命中断点。尚未为此文档加载任何符号”

60
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文