相关文章推荐
傻傻的针织衫  ·  (Solved)error getting ...·  1 年前    · 
憨厚的感冒药  ·  ComboBox和SelectedIndex ...·  1 年前    · 
乖乖的皮带  ·  C++ ...·  1 年前    · 
从未表白的柠檬  ·  VS2017 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

how to fix "Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled."

Ask Question

I'm getting this error when trying to run my Java code with Maven using Intellij:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2022-06-29 23:39:33.179 ERROR 4068 --- [ main] o.s.boot.SpringApplication : Application run failed

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.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.server.app</groupId>
    <artifactId>rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>RestAPI</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-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <!--> mysql on my computer version, the version should be true<-->
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.26</version>
        </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>

RestApi.java

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class RestApiApplication { public static void main(String[] args) { SpringApplication.run(RestApiApplication.class, args);

User.java

package com.server.app.rest.Models;
import javax.persistence.*;
// mysql columns, connection
@Entity
public class User {
    // id is primary key
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column
    private String firstName;
    @Column
    private String lastName;
    @Column
    private String job;
    public long getId() {
        return id;
    public void setId(long id) {
        this.id = id;
    public String getFirstName() {
        return firstName;
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    public String getLastName() {
        return lastName;
    public void setLastName(String lastName) {
        this.lastName = lastName;
    public String getJob() {
        return job;
    public void setJob(String job) {
        this.job = job;

UserRepo.java

import com.server.app.rest.Models.User; import org.springframework.data.jpa.repository.JpaRepository; //userrepo get features from jpa. public interface UserRepo extends JpaRepository<User, Long> {

properies

spring.datasource.url=jdbc:mysql://localhost:3306/crudusers?allowPublicKeyRetrieval=true&useSSL=false

spring.datasource.username=username

spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=update

ApiControllers.java

import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class ApiControllers { // first connect the page, except this- / - get error @GetMapping(value = "/") public String getPage(){ return "Welcome"; accept the solution as the answer, you will see the check or good button under the vote buttons. – Obumuneme Nwabude Jul 2, 2022 at 14:54

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.