@reactive93

Spring boot не видит интефейс JpaRepository?

Всем привет учу spring boot и столкнулся с проблемой соединения с базой данных
вот все настройки
spring.properties
security.basic.enabled=false
spring.datasource.url=jdbc:mysql://localhost:3306
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

kotlin
@Repository
interface EmploeeRepository: JpaRepository<Emploee, Int> {

    fun findById(id:Int):Emploee

}

@Entity()
@Table(name="robot1")
open class Emploee:Serializable
{
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name="id")
        var id:Int =0

        @Column(name = "name")
        var name:String=""

        @Column(name="surname")
        var surname:String=""
}

@Autowired
   lateinit var rep:EmploeeRepository

    
    @RequestMapping("/index")
    fun index( model: Model):String
    {

        println(rep.findById(1).name)

        println( )
        return "index"
    }

<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>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-stdlib-jre8</artifactId>
			<version>${kotlin.version}</version>
		</dependency>

		<dependency>
			<groupId>org.jetbrains.kotlin</groupId>
			<artifactId>kotlin-reflect</artifactId>
			<version>${kotlin.version}</version>
		</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>

Вот собственно ошибка :
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainController': Unsatisfied dependency expressed through field 'rep'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.data.EmploeeRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

над главным классом весит аннотация @ComponentScan("com.config","com.controllers","com.data")
то есть он должен видеть
  • Вопрос задан
  • 1636 просмотров
Решения вопроса 1
@reactive93 Автор вопроса
Проблема решена над главным классом добавил
@EnableJpaRepositories(basePackages = arrayOf("com.data"))
@EntityScan("com.data")
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы