Почему я получаю сообщение об ошибке при запуске приложения Spring Boot, которое определяет bean-компонент типа com.examJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Гость
 Почему я получаю сообщение об ошибке при запуске приложения Spring Boot, которое определяет bean-компонент типа com.exam

Сообщение Гость »

Код: Выделить всё

package com.exam.examserver;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

import com.exam.models.Role;
import com.exam.models.User;
import com.exam.models.UserRole;
import com.exam.service.UserService;

@ComponentScan({"com.exam.service"})
@SpringBootApplication
public class ExamserverApplication implements CommandLineRunner {

@Autowired
private UserService userService ;

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

@Override
public void run(String... args) throws Exception {
System.out.println("starting");

User user=new User();
user.setFirstName("yogender");
user.setLastName("sharma");
user.setUserName("yogen139");
user.setPassword("abc");
user.setEmail("abc@gmail.com");

Role role1= new Role();
role1.setRoleId(44L);
role1.setRoleName("Admin");

Set userRoleSet= new HashSet();
UserRole userRole= new UserRole();
userRole.setRole(role1);
userRole.setUser(user);
User user1= this.userService.CreateUser(user, userRoleSet);

System.out.println(user1.getUserName());
}
}

Код: Выделить всё

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

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

Description:
Field userRepo in com.exam.service.UserServiceImpl required a bean
of type 'com.exam.repo.UserRepository' that could not be found.

The injection point has the following annotations:

@org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'com.exam.repo.UserRepository' in
your configuration.`
Эта ошибка появляется на консоли при попытке запустить приложение. Я определил репозиторий пользователей с помощью нотации @Repository. Вот структура проекта:
(Изображение)
Если кто-нибудь может помочь я в этом.
Я запускаю его в SpringToolSuite и использую базу данных MySQL. Выполнил различные действия по устранению неполадок.

Подробнее здесь: https://stackoverflow.com/questions/781 ... ne-bean-of
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»