Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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
Java org.springframework.beans.factory.BeanCreationException:错误如何解决此问题?_Java_Spring_Hibernate_Spring Boot - Fatal编程技术网

Java org.springframework.beans.factory.BeanCreationException:错误如何解决此问题?

Java org.springframework.beans.factory.BeanCreationException:错误如何解决此问题?,java,spring,hibernate,spring-boot,Java,Spring,Hibernate,Spring Boot,我需要一些帮助。我将Java与Springboot结合使用,我正在从事一个项目,该项目主要将数据库中的信息(书名、作者、语言等)显示在网页上,通过浏览网站,我可以对数据库进行更改,如编辑条目、创建新条目、显示条目或删除条目 它工作得很好,直到我不得不关闭我的计算机,然后当我返回并试图再次运行该项目时,它给了我下面的错误以及许多其他文本。我重新启动了服务器,在调试模式下运行,似乎什么都没用。这几乎就像我打破了以前的某种联系,或者我删除了一些我不应该删除的东西。我只是不知道会是什么。我希望任何人都能

我需要一些帮助。我将Java与Springboot结合使用,我正在从事一个项目,该项目主要将数据库中的信息(书名、作者、语言等)显示在网页上,通过浏览网站,我可以对数据库进行更改,如编辑条目、创建新条目、显示条目或删除条目

它工作得很好,直到我不得不关闭我的计算机,然后当我返回并试图再次运行该项目时,它给了我下面的错误以及许多其他文本。我重新启动了服务器,在调试模式下运行,似乎什么都没用。这几乎就像我打破了以前的某种联系,或者我删除了一些我不应该删除的东西。我只是不知道会是什么。我希望任何人都能告诉我我可能做错了什么,这样我就可以扭转它,让它重新运行起来

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2m2020-03-16 23:06:05.766[0;39m [31mERROR[0;39m [35m49106[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application run failed

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]
请注意,我并没有直接了解“hibernate”,只是在我看到这个错误并尝试用谷歌搜索答案时才听说这个术语。我尝试了stackoverflow中提到的其他一些解决方案,这些解决方案适用于有类似问题的人,但对我来说不起作用(即,添加了一个关于hibernate的特定依赖项,但我现在记不清其中的细节)

下面是我用于各种软件包的一些代码:

财产

在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.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.blank.mvc2</groupId>
    <artifactId>mvc2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mvc2</name>
    <description>mvc2</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>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
    </dependencies>

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

</project>
在存储库包中:

import java.util.List;
import java.util.Optional;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BookRepository extends CrudRepository<Book, Long> {
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

@Service
public class BookService {
import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class BooksController {
在控制器包中:

import java.util.List;
import java.util.Optional;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BookRepository extends CrudRepository<Book, Long> {
import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Service;

@Service
public class BookService {
import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class BooksController {

请注意,我已经做了这个项目,并且为了练习再次做了这个项目,两个项目以前都工作过,但现在两个项目都不工作了。在我重新启动我的计算机之前,它工作得很好(在这段时间内,计算机本身没有更新)。如果你想要更多的信息,请告诉我。我现在只需要帮助我弄明白这一点,因为我不明白为什么它会在一分钟内工作,然后简单地打开/关闭电脑,它在下一分钟就不工作了。

好的,所以什么都没用,在网上做了更多的挖掘之后,我找到了一个解决方案,但不知道如何实现它,甚至不知道它是否可行。果然,我找到了一段Youtube视频(),他在视频中一步一步地解释了这个问题,以及如何解决这个问题

TLDR:我最初拥有
spring.datasource.url=jdbc:mysql://localhost:3306/book-架构
,但出现了几个错误,其中一个错误是EDT不是可识别的时区。这似乎是导致其他错误的原因

因此,我现在在properties中看到的是:

spring.datasource.url=jdbc:mysql://localhost:3306/book-schema?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
该程序现在的工作原理与以前一样。(我想可能是3月8日的夏令时起了作用?我不知道,但它工作正常,然后突然说它不识别EDT。)


感谢所有试图帮助我解决此问题的人。

能否添加您的属性文件。需要查看数据库配置。我将把它添加到主帖子中,因为它的格式不如评论中的响应。在底部。我想您能够显式连接数据库吗?我面前有数据库,我正在使用WorkBench。我有前几天它最后一次工作时的条目。您是否尝试将驱动程序类替换为com.mysql.cj.jdbc.driver并从POM.xml中的MysqlConnector中删除作用域