inicialização Primavera Campo necessário um feijão do tipo que não pôde ser encontrado

xhallix:

Eu vou até o tutorial arranque JPA para inicialização primavera estou lutando. Eu sei que a pergunta foi feita, por vezes aqui ( 'Campo necessário um feijão do tipo que não pôde ser encontrado.' Primavera de erro API RESTful usando mongodb )

Mas esses problemas são um pouco diferente do que eu tenho.

Estrutura

java
  |
  helloWorld
  |
  web/ -- HelloWorldController
  Application
  Customer
  CustomerRepository
  ServletInitializer

Como você pode ver todos os meus pacotes relacionados ao JPA estão no mesmo nível que o meu arquivo do aplicativo. De acordo com o tutorial ( https://spring.io/guides/gs/accessing-data-jpa/ ) isso deve funcionar

Minha classe Application

package helloWorld;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    CustomerRepository customerRepository;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

CustomerRepository

package helloWorld;


import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface CustomerRepository extends CrudRepository<Customer, Long> {

    List<Customer> findByLastName(String lastName);
}

Ao tentar usar @Autowiredrecebo

***************************
APPLICATION FAILED TO START
***************************

Description:

Field customerRepository in helloWorld.Application required a bean of type 'helloWorld.CustomerRepository' that could not be found.


Action:

Consider defining a bean of type 'helloWorld.CustomerRepository' in your configuration.

Além disso, a adição scanBasePackages={"helloWorld"})de @SpringBootApplicationnão ajudar e, pelo que eu li, não deve também ser necessário.

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>helloWorld.com.example</groupId>
    <artifactId>helloWorld</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

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

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.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>com.h2database</groupId>
            <artifactId>h2</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>
        </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>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>1.1.0</version>
                <configuration>
                    <resourceGroup>maven-projects</resourceGroup>
                    <appName>${project.artifactId}-${maven.build.timestamp}</appName>
                    <region>westus</region>
                    <javaVersion>1.8</javaVersion>
                    <deploymentType>war</deploymentType>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

link para o projeto github

Andrew Tobilko:

Você está excluindo a configuração automática de repositórios JPA. Remova a linha de application.propertiesdeixar Primavera fazer CustomerRepositoryum feijão e configurá-lo.

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

Acho que você gosta

Origin http://43.154.161.224:23101/article/api/json?id=191693&siteId=1
Recomendado
Clasificación