mysql - 运行spring boot应用程序时出错

标签 mysql spring spring-boot spring-data-jpa

我尝试了 Spring boot 的 web 应用程序。当我尝试启动服务器时,我收到一条错误消息:

我在网上找不到任何类似的帖子,所以我引用了 stackoverflow。 提前致谢!!

2017-07-14 10:37:47.525  WARN 10452 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property lastName found for type User!
2017-07-14 10:37:47.525  INFO 10452 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-07-14 10:37:47.525  INFO 10452 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-07-14 10:37:47.540  INFO 10452 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-07-14 10:37:47.540 ERROR 10452 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [ 

应用程序属性:

spring.datasource.url = jdbc:mysql://localhost:3306/test?verifyServerCertificate=false&useSSL=false&requireSSL=false
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.username=Stack0verFlow
spring.datasource.password=Stack0verFlow
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.thymeleaf.cache=false

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.flowcode</groupId>
    <artifactId>WebApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>WebApp</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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


</project>

最佳答案

正如评论中提到的,异常的某些部分丢失了。但是,问题也可以在堆栈跟踪的第一行中找到:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository

还有:

org.springframework.data.mapping.PropertyReferenceException: No property lastName found for type User!

因此,您应该检查您的 UserRepository,因为您有一个查询或方法名称引用名为 lastName 的属性,即使您的数据库中没有该属性。 用户实体。

关于mysql - 运行spring boot应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45098635/

相关文章:

python - 如何在 Django 中从 models.py 查询数据库项?

java - 使用 spring-hateoas 反序列化包含(_links 和 _embedded)的 JSON

java - 如何在 SpEL 中进行日期操作?

multithreading - 在运行线程中 Autowiring 或注入(inject) Bean

spring-boot - Gradle 多模块项目 java.lang.NoClassDeffFoundError

java - 如何直接从Spring Boot应用程序将文件上传到azure blob存储,而不将文件放入内存(缓冲内存)

php - Mysql 数据在选择列表中的单引号后被截断

mysql - 从多个候选键中选择

mysql - 如何合并mysql存储过程中的行?

Spring Boot 和 Log4j 问题