无法执行目标 org.springframework.boot:spring-boot-..:2.1.8。 运行 时发生异常。无效的
Failed to execute goal org.springframework.boot:spring-boot-..:2.1.8. An exception occurred while running. null
我是 SpringMVC 的新手,被困在这里。
我通过 Spring Initializr 创建了一个 Spring Boot 应用程序,然后
创建 HomeController
,将其连接到 index.jsp
。它正在工作
很好,但是当我添加 SearchController
、连接 search.jsp
时,它
现在不工作。在添加 SearcController
之前,应用程序是
运行宁很好,但它说:
无法在项目 hplus 上执行目标...插件:2.4.0:运行(默认 cli):应用程序已完成,退出代码为:1
Update: 在做了一些搜索后我发现我的数据库服务器
不是 运行ning,在 运行ning 之后,运行ning 我的申请是
测试,报错。
访问DialectResolutionInfo时不能为null
'hibernate.dialect' 未设置
.
Full Error!
Test set:HplusappApplicationTests
<<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
.
pom.xml file ->
<code>
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.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>spring-example</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>myapp</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>
application.properties ->
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/hplus
spring.datasource.username=root
spring.datasource.password=root
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
它清楚地表明你输入了一个错误的mvn
命令。 你执行的命令是什么?
我们一般运行mvn clean install
来构建一个应用。
以下是可能对您有所帮助的 Maven commands 列表。
您需要指定 MySQL Hibernate 应使用的方言:
将其放入 application.properties:
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
在定义 bean 和你的 pom 文件时似乎有错误,你是否尝试过 运行 全新安装,
mvn clean instal
命令?如果仍然不起作用,请尝试查看您的 pom 和 application.properties 文件是否还有一些混合版本?如果仍然不起作用,请尝试删除您的 .m2 文件并再次 运行 mvn clean install。
解决方案
找了两天多,发现是timeZone的问题
我编辑了 application.properties,第二行 ->
spring.datasource.url=jdbc:mysql://localhost:3306/hplus?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
问题解决了。
我是 SpringMVC 的新手,被困在这里。
我通过 Spring Initializr 创建了一个 Spring Boot 应用程序,然后
创建 HomeController
,将其连接到 index.jsp
。它正在工作
很好,但是当我添加 SearchController
、连接 search.jsp
时,它
现在不工作。在添加 SearcController
之前,应用程序是
运行宁很好,但它说:
无法在项目 hplus 上执行目标...插件:2.4.0:运行(默认 cli):应用程序已完成,退出代码为:1
Update: 在做了一些搜索后我发现我的数据库服务器 不是 运行ning,在 运行ning 之后,运行ning 我的申请是 测试,报错。
访问DialectResolutionInfo时不能为null 'hibernate.dialect' 未设置 .
Full Error!
Test set:HplusappApplicationTests
<<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
.
pom.xml file ->
<code>
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.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>spring-example</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>myapp</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>
application.properties ->
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/hplus
spring.datasource.username=root
spring.datasource.password=root
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
它清楚地表明你输入了一个错误的mvn
命令。 你执行的命令是什么?
我们一般运行mvn clean install
来构建一个应用。
以下是可能对您有所帮助的 Maven commands 列表。
您需要指定 MySQL Hibernate 应使用的方言:
将其放入 application.properties:
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
在定义 bean 和你的 pom 文件时似乎有错误,你是否尝试过 运行 全新安装,
mvn clean instal
命令?如果仍然不起作用,请尝试查看您的 pom 和 application.properties 文件是否还有一些混合版本?如果仍然不起作用,请尝试删除您的 .m2 文件并再次 运行 mvn clean install。
解决方案 找了两天多,发现是timeZone的问题
我编辑了 application.properties,第二行 ->
spring.datasource.url=jdbc:mysql://localhost:3306/hplus?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
问题解决了。