A
A
Anatoly2017-06-02 15:41:30
Java
Anatoly, 2017-06-02 15:41:30

Spring boot not seeing JpaRepository interface?

Hello everyone, I'm learning spring boot and ran into a problem connecting to the database,
here are all the
spring.properties settings

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>

Here is the actual error:
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)}
the @ComponentScan("com.config","com.controllers","com.data") annotation weighs over the main class,
i.e. he must see

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2017-06-02
@reactive93

Problem solved over main class added

@EnableJpaRepositories(basePackages = arrayOf("com.data"))
@EntityScan("com.data")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question