...“在项目Jwplusapp上:运行时发生异常。为空”
有人知道为什么我不能通过Maven选择“ spring-boot:run”而没有得到该错误吗? 香港专业教育学院试图重命名数据库文件,还确保父版本正确。我试图检查pom.xml,但我想我只是想念它。任何有关此错误代码的帮助将不胜感激。是的,我看到过类似的帖子,但他们似乎并没有为我解决问题。
POM XML
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>Jwplusapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Jwplusapp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
应用程序。属性
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/Jwplus
spring.datasource.username=root
spring.datasource.password=root
ApplicationConfig.java
package com.test.Jwplusapp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@ComponentScan(basePackages = "com.test.Jwplusapp")
public class ApplicationConfig extends WebMvcConfigurationSupport {
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("css/**", "images/**")
.addResourceLocations("classpath:/static/css/", "classpath:/static/images/");
}
@Bean
public InternalResourceViewResolver jspViewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
viewResolver.setViewClass(JstlView.class);
return viewResolver;
}
}
答案 0 :(得分:0)
我尝试使用您的pom.xml,它对我有用。仅当您拥有相同的端口(8080或应用程序中使用的端口)时,它才会失败,并显示相同的错误。
能否请您检查要运行的端口的可用性(如果已占用端口,请尝试在其他端口上运行或杀死该端口)。
您还可以将完整错误粘贴到堆栈跟踪中的“ null”之后。
已更新:
确保您的项目中具有以下属性
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_examplele
spring.datasource.username=springuser
spring.datasource.password=ThePassword
如果使用的是jpa,请尝试以下配置
@Configuration
public class HibernateConfig {
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
factory.setEntityManagerFactory(emf);
return factory;
}
}
答案 1 :(得分:0)
原来的解决方案不是因为我的代码错误,而是解决方案是下载MySQL Installer-MySQL
这是下载链接
在检查我的服务并注意到未显示MYSQL80服务时我发现了这一点。(已检查服务,也是任务管理器->服务)
然后安装了我的设备中缺少的MySQL80服务,然后允许我的“ spring-boot:run”成功处理并打开我的功能齐全的网页,同时连接到所需的localhost 3306并完全连接到MYSQL上的root工作台。