当前位置: 首页 > 知识库问答 >
问题:

使用Spring MVC运行Sprint引导时引发Nullpointer异常

闻人栋
2023-03-14
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
  </parent>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.0.1.RELEASE</version>
    </dependency>


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

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.0.1.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>1.5.8.RELEASE</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>azzimov-search</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>

    </plugins>

    <resources>
      <resource>
        <directory>src/clients</directory>
      </resource>
    </resources>
  </build>
<webapp>
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/web-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/gw/*</url-pattern>
  </servlet-mapping>
</web-app>

我的web-config.xml是

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd ">

    <mvc:annotation-driven />
    <context:component-scan base-package="com.project.book" />
</beans>

共有1个答案

桑璞
2023-03-14

您正在尝试将Spring Boot1.5与Spring5混合使用。这不会以这种方式工作,因为它们不兼容。如果您真的需要Spring Framework5,您应该使用Spring Boot2.x starter父级。

根据您的需要,您可以使用下面的pom.xml并将1.5.8.release更改为2.0.0.m5,或者保持原样。

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
<build>
    <finalName>azzimov-search</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

    </plugins>

    <resources>
        <resource>
            <directory>src/clients</directory>
        </resource>
    </resources>
</build>

请注意,我从依赖项中删除了版本,因此它们是从父starter中提取的。

@SpringBootApplication
public class BookApp {

    public static void main(String[] args) {
         SpringApplication.run(BookApp.class, args);
    }
}
 类似资料:
  • editable.FTL 什么是正确的方法来导入到我的模板。我尝试使用cfg.addautoimport(“me”,“editable.ftl”)。当我试图处理我的主模板时,会引发以下异常。 错误[FreeMarker.runtime](http-localhost-127.0.0.1-8080-1)执行FreeMarker模板时出错:FreeMarker.core.InvalidReferenc

  • 下面是我生成PDF的代码: 下面是我用来绘制多个字符串的代码: 此代码正常工作,但如果我将更改为,它将引发以下异常: 起初,我认为这是因为有些数据不存在,无法编写,但如果我不更新Voly,它就可以正常工作。然后我认为这是一个问题,当创建了一个新页面但流存在时,没有创建PDPageContentStream。 提前感谢您的帮助!

  • 我尝试了很多方法在片段视图中成功实现了onitemselectedlistener,但不断地得到一个致命的java异常。它始终指向代码中的同一行,用于为spinner设置onitemselectedlistener方法。 android studio logcat错误输出为: 07-21 13:55:06.544 17277-17277/com。vaibhavtech。indoreveg E/An

  • 我通过REST使用SpringData和Neo4j,当我添加@Indexed(unique=true)时,我看到了一个异常。这不会在embedded中引发异常,如果删除unique=true,也不会在REST中引发异常。即使数据库为空(没有节点和索引),也会发生这种情况。 有什么想法吗? 以下是异常跟踪: 为了完整起见,下面是测试代码:

  • 我一直在开发这个简单的Java程序,在某种程度上它抛出了一个“ClassCastException”,我不知道为什么。程序中发生的事情是,它读取2个文本文件,并将它们存储在对象数组列表中(因为我使用相同的方法读取这两个文件) 稍后,当我尝试将这些对象转换为我创建的自定义数据类型时,程序会抛出此错误。我做错了什么? } ^^这需要与员工相关的菜单。 ^^这就是我得到异常的地方,就在“客户客户=(客户