Я знаю, что этот вопрос иногда задавался здесь ('Поле требуется компонент типа, который не удалось найти.' ошибка Spring RESTful API с использованием MongoDB)
Но эти проблемы немного отличаются от тех, что есть у меня.
Структура
Код: Выделить всё
java
|
helloWorld
|
web/ -- HelloWorldController
Application
Customer
CustomerRepository
ServletInitializer
Класс моего приложения
Код: Выделить всё
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);
}
}
Код: Выделить всё
package helloWorld;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface CustomerRepository extends CrudRepository {
List findByLastName(String lastName);
}
Код: Выделить всё
***************************
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.
Код: Выделить всё
pom.xmlКод: Выделить всё
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
helloWorld.com.example
helloWorld
0.0.1-SNAPSHOT
war
fireCommerce
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-data-jpa
com.h2database
h2
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-devtools
runtime
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
com.microsoft.azure
azure-webapp-maven-plugin
1.1.0
maven-projects
${project.artifactId}-${maven.build.timestamp}
westus
1.8
war
Подробнее здесь: https://stackoverflow.com/questions/521 ... t-be-found
Мобильная версия