Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
路径为[/path]的上下文中Servlet[Jersey Web Application]的Servlet.service()引发了具有根本原因的异常[java.lang.NullPointerException]_Java_Rest - Fatal编程技术网

路径为[/path]的上下文中Servlet[Jersey Web Application]的Servlet.service()引发了具有根本原因的异常[java.lang.NullPointerException]

路径为[/path]的上下文中Servlet[Jersey Web Application]的Servlet.service()引发了具有根本原因的异常[java.lang.NullPointerException],java,rest,Java,Rest,任何人都可以帮助解决以下空指针异常时,试图击中邮递员应用程序。下面是资源类web.xml、pom.xml类。在资源类中的此行“return commonManager.calculateFixedDeposit”引发异常 package com.bank.resource; import javax.annotation.Resource; import javax.inject.Named; import javax.ws.rs.Consumes; impo

任何人都可以帮助解决以下空指针异常时,试图击中邮递员应用程序。下面是资源类web.xml、pom.xml类。在资源类中的此行“return commonManager.calculateFixedDeposit”引发异常

 package com.bank.resource;

    import javax.annotation.Resource;
    import javax.inject.Named;
    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 com.bank.beans.Deposit;
    import com.bank.beans.DepositResponse;
    import com.bank.common.CommonManager;
    import com.bank.common.Constants;

    @Named
    @Path(Constants.API)
    public class FixedDepositResource {

        @Resource
        CommonManager commonManager;

        @POST
        @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        @Path(Constants.FIXED_DEPOSIT)
        public DepositResponse fixedDepositResult(Deposit deposit) {

            return commonManager.calculateFixedDeposit(deposit.getPrincipal(),
                    deposit.getRateOfInterest(), deposit.getNoOfDays());

        }
    }
在调试代码时,可以看出这是由于

/**
 * Constructs a InvocationTargetException with a target exception.
 *
 * @param target the target exception
 */
public InvocationTargetException(Throwable target) {
    super((Throwable)null);  // Disallow initCause
    this.target = target;
}
资源类

 package com.bank.resource;

    import javax.annotation.Resource;
    import javax.inject.Named;
    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 com.bank.beans.Deposit;
    import com.bank.beans.DepositResponse;
    import com.bank.common.CommonManager;
    import com.bank.common.Constants;

    @Named
    @Path(Constants.API)
    public class FixedDepositResource {

        @Resource
        CommonManager commonManager;

        @POST
        @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
        @Path(Constants.FIXED_DEPOSIT)
        public DepositResponse fixedDepositResult(Deposit deposit) {

            return commonManager.calculateFixedDeposit(deposit.getPrincipal(),
                    deposit.getRateOfInterest(), deposit.getNoOfDays());

        }
    }
Web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
      <display-name>bankapplication</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
        <servlet>
            <servlet-name>Jersey Web Application</servlet-name>
            <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
            <init-param>
                <param-name>jersey.config.server.provider.packages</param-name>
                <param-value>com.bank</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
            <servlet-name>Jersey Web Application</servlet-name>
            <url-pattern>/rest/*</url-pattern>
        </servlet-mapping>
    </web-app>
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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>bankapplication</groupId>
  <artifactId>bankapplication</artifactId>
  <version>0.0.1-SNAPSHOT</version>

 <dependencies>

   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.0.0.RELEASE</version>
   </dependency>

  <dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
  </dependency>

  <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.22.2</version>
  </dependency>

  <dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.22.2</version>  <!-- make sure the jersey version 
                                  matches the one you are using -->
</dependency>

</dependencies>



  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

4.0.0
银行申请
银行申请
0.0.1-快照
org.springframework
spring上下文
4.0.0.0发布
javax.ws.rs
javax.ws.rs-api
2
javax.inject
javax.inject
1.
org.glassfish.jersey.containers
jersey容器servlet
2.22.2
org.glassfish.jersey.media
泽西媒体公司
2.22.2  
src
maven编译器插件
3.1
1.8
1.8

请在这方面提供帮助,因为我在过去两天里一直在使用它。我尝试在此参数
com.bank
-->
com.bank.resource
中输入完整的包名,但它不起作用。在我的例子中,问题是无法转到资源类,因为它在FixedDepositResource中的CalculateExedDeposit中执行此方法时失败,