Home > Enterprise >  Spring Boot JPA with MySQL - cannot create controller bean due to dependency issue
Spring Boot JPA with MySQL - cannot create controller bean due to dependency issue

Time:12-05

I'm working through various aspects of Spring Boot in the last few days and today I've been frustrated by JpaRepository. The example is introductory, MySQL JPA, built around the MVC design. I've a previous MySQL integration with Core Java, but not Spring Boot.

The code is as follows:

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.fanshawe</groupId>
    <artifactId>springboot-mysql-jpa-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-mysql-jpa-demo</name>
    <description>Demo project for Spring Boot, Maven, Spring JPA and MySQL</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>
        
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

BlogRepo.java:

package com.example.springbootmysqljpademo.repo;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
//to import quickly, click Ctrl-Shift-O
import org.springframework.stereotype.Repository;

import com.example.springbootmysqljpademo.model.Blog;

@Repository
public interface BlogRepo extends JpaRepository<Blog, Integer>{
    
    List<Blog> findByTitleContainingOrContentContaining(String text, String textAgain);

    Blog findOne(int blogId);

}

Blog.java:

package com.example.springbootmysqljpademo.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Blog {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    
    private String title;
    private String content;
    
    public Blog() {
    
        // TODO Auto-generated constructor stub
    }
    
    public Blog(String title, String content) {
        
        this.setTitle(title);
        this.setContent(content);
    }
    
    public Blog(int id, String title, String content) {
    
        this.setId(id);
        this.setTitle(title);
        this.setContent(content);
    }
    
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    
    @Override
    public String toString() {
        return "Blog [id="   id   ", title="   title   ", content="   content   "]";
    }

}

BlogController.java:

package com.example.springbootmysqljpademo.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.springbootmysqljpademo.model.Blog;
import com.example.springbootmysqljpademo.repo.BlogRepo;

@RestController
public class BlogController {
    
    @Autowired
    BlogRepo blogRepo;
    
    @GetMapping("/blog")
    public List<Blog> displayAllBlogs() {
        return blogRepo.findAll();
    }
    
    @GetMapping("/blog/{id}")
    public Blog show(@PathVariable String id) {
        
        int blogId = Integer.parseInt(id);
        
        return blogRepo.findOne(blogId);
    }
    
    @PostMapping("/blog/search")
    public List<Blog> searchBlogs(@RequestBody Map<String, String> body) {
        String searchTerm = body.get("text");
        return blogRepo.findByTitleContainingOrContentContaining(searchTerm, searchTerm);
    }
    
    @PostMapping("/blog")
    public Blog create(@RequestBody Map<String, String> body) {
        
        String title = body.get("title");
        String content = body.get("content");
        
        return blogRepo.save(new Blog(title, content));
        
    }
    
    @PutMapping("/blog/{id}")
    public Blog update(@PathVariable String id, @RequestBody Map<String, String> body) {
        
        int blogId = Integer.parseInt(id);
        
        Blog blog = blogRepo.findOne(blogId);
        
        blog.setTitle(body.get("title"));
        blog.setContent(body.get("content"));
        
        return blogRepo.save(blog);
    }
    
    @DeleteMapping("/blog/{id}")
    public boolean delete(@PathVariable String id) {
        
        int blogId = Integer.parseInt(id);
        
        blogRepo.deleteById(blogId);
        
        return true;
    }

}

and the main app file:

package com.example.springbootmysqljpademo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@ComponentScan
@EnableJpaRepositories
public class SpringbootMysqlJpaDemoApplication {

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

}

application.properties for the mysql configuration:

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/new_db
spring.datasource.username=root
spring.datasource.password=password

The stack trace:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blogController': Unsatisfied dependency

expressed through field 'blogRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogRepo' defined in com.example.springbootmysqljpademo.repo.BlogRepo defined in @EnableJpaRepositories declared on SpringbootMysqlJpaDemoApplication: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int); Reason: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog'; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog' at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.23.jar:5.3.23] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.5.jar:2.7.5] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.5.jar:2.7.5] at com.example.springbootmysqljpademo.SpringbootMysqlJpaDemoApplication.main(SpringbootMysqlJpaDemoApplication.java:14) ~[classes/:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.7.5.jar:2.7.5] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogRepo' defined in com.example.springbootmysqljpademo.repo.BlogRepo defined in @EnableJpaRepositories declared on SpringbootMysqlJpaDemoApplication: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int); Reason: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog'; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog' at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.23.jar:5.3.23] ... 25 common frames omitted Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int); Reason: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog'; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog' at org.springframework.data.repository.query.QueryCreationException.create(QueryCreationException.java:101) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:107) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(QueryExecutorMethodInterceptor.java:95) ~[spring-data-commons-2.7.5.jar:2.7.5] at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na] at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na] at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1052) ~[na:na] at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na] at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.mapMethodsToQuery(QueryExecutorMethodInterceptor.java:97) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lambda$new$0(QueryExecutorMethodInterceptor.java:87) ~[spring-data-commons-2.7.5.jar:2.7.5] at java.base/java.util.Optional.map(Optional.java:265) ~[na:na] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.(QueryExecutorMethodInterceptor.java:87) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:365) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:323) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.util.Lazy.getNullable(Lazy.java:231) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.util.Lazy.get(Lazy.java:115) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:329) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:144) ~[spring-data-jpa-2.7.5.jar:2.7.5] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.23.jar:5.3.23] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.23.jar:5.3.23] ... 35 common frames omitted Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.springbootmysqljpademo.model.Blog com.example.springbootmysqljpademo.repo.BlogRepo.findOne(int)! No property 'findOne' found for type 'Blog' at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:96) ~[spring-data-jpa-2.7.5.jar:2.7.5] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:119) ~[spring-data-jpa-2.7.5.jar:2.7.5] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:259) ~[spring-data-jpa-2.7.5.jar:2.7.5] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93) ~[spring-data-jpa-2.7.5.jar:2.7.5] at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:103) ~[spring-data-commons-2.7.5.jar:2.7.5] ... 57 common frames omitted Caused by: org.springframework.data.mapping.PropertyReferenceException: No property 'findOne' found for type 'Blog' at org.springframework.data.mapping.PropertyPath.(PropertyPath.java:91) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:438) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:414) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.mapping.PropertyPath.lambda$from$0(PropertyPath.java:367) ~[spring-data-commons-2.7.5.jar:2.7.5] at java.base/java.util.concurrent.ConcurrentMap.computeIfAbsent(ConcurrentMap.java:330) ~[na:na] at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:349) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:332) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.query.parser.Part.(Part.java:81) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:250) ~[spring-data-commons-2.7.5.jar:2.7.5] at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na] at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[na:na] at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na] at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na] at org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:251) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:384) ~[spring-data-commons-2.7.5.jar:2.7.5] at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na] at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177) ~[na:na] at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na] at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na] at org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:385) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.repository.query.parser.PartTree.(PartTree.java:93) ~[spring-data-commons-2.7.5.jar:2.7.5] at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:89) ~[spring-data-jpa-2.7.5.jar:2.7.5] ... 61 common frames omitted

This is what I've tried to resolve it:

  1. Changed the table name in the MySQL table to match the rest
  2. Fields, Column names, are all aligned.
  3. Added @ComponentScan to the main class - I think I don't think to further concretize it in its parameters. The base package would be the main class, no?
  4. Added @EnableJpaRepositories to the main class, as well.
  5. Checked dependencies - added javax.api, which is a top solution that had no effect.
  6. my-sql-connector-j, is a recent innovation vis-a-vis the version used in the example.
  7. One change against the original is Blog findOne(int blogId);, because the code had a problem using findById vs. findOne methods, so I had to do it this way to use the findOne method.
  8. @Controller needs to be @RestController to compile properly.
  9. I do have the @Repository annotation atop the respective class.
  10. The project was not organized in packages originally, but I've made that adjustment.
  11. No slashes missing in any of the mapping...
  12. I don't think a service component is necessary, per se? It outsources the methods in the controller, from which they will be invoked anyway.
  13. Checked out these links:

Unsatisfied dependency exception

JPA Crud Repo

Spring cannot create bean

Beyond this, I'm suspecting that it's an issue with the way I've done the annotations, though nothing stands out at me after reading through various sources, even if I don't have the most sophisticated understanding of them. At this point, I'm at a general loss how to approach it.

Thank you in advance!

CodePudding user response:

with component scan you are supposed to add base package too, before doing that try out putting em all in one package that would tell you if its an issue with packaging. https://www.baeldung.com/spring-unsatisfied-dependency, this link covers reason for UnsatisfiedDependencyException, check it out if you haven't.

  • Related