0

I'm learning Spring Boot at the moment. I'm trying to insert some data in a mysql table using Spring Data Jpa. When I try to create my autowired repository interface I get this problem while running my application.

I got this error in the ReflectionUtils class:

Error creating bean with name 'frontcontroller': Unsatisfied dependency expressed through field 'databaseaction'

In my console i got this error:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.19.RELEASE)

2019-03-26 17:38:54.761  INFO 5744 --- [           main] com.example.demo3.Demo3Application       : Starting Demo3Application on IT-85 with PID 5744 (E:\RapidJava\SpringBootProject\demo-3\target\classes started by Nagaraju in E:\RapidJava\SpringBootProject\demo-3)
2019-03-26 17:38:54.779  INFO 5744 --- [           main] com.example.demo3.Demo3Application       : No active profile set, falling back to default profiles: default
2019-03-26 17:38:54.890  INFO 5744 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@d554c5f: startup date [Tue Mar 26 17:38:54 IST 2019]; root of context hierarchy
2019-03-26 17:38:56.515  INFO 5744 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$4b71926e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-26 17:38:56.998  INFO 5744 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-03-26 17:38:57.042  INFO 5744 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-03-26 17:38:57.042  INFO 5744 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.37
2019-03-26 17:38:57.243  INFO 5744 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2019-03-26 17:38:57.247  INFO 5744 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-03-26 17:38:57.247  INFO 5744 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2360 ms
2019-03-26 17:38:57.458  INFO 5744 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2019-03-26 17:38:57.463  INFO 5744 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-03-26 17:38:57.463  INFO 5744 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-03-26 17:38:57.464  INFO 5744 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-03-26 17:38:57.464  INFO 5744 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-03-26 17:38:57.590  WARN 5744 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'frontcontroller': Unsatisfied dependency expressed through field 'databaseaction'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'databaseaction': Cannot create inner bean '(inner bean)#7c9bdee9' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#7c9bdee9': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2019-03-26 17:38:57.593  INFO 5744 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-03-26 17:38:57.841  INFO 5744 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-03-26 17:38:57.904 ERROR 5744 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field databaseaction in com.example.demo3.controller.Frontcontroller required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

How do I rectify this problem. I'm using IDE STS-4

Source code:

Controller class:

package com.example.demo3.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo3.model.usermodel;
import com.example.demo3.repository.Databaseaction;

@Controller
public class Frontcontroller {
    @Autowired
    Databaseaction databaseaction;

    @RequestMapping("/")
    public String getreq() {
        System.out.println("method called");
        return "index";
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public ModelAndView save(usermodel user) {
        ModelAndView mv = new ModelAndView();
        try {
            databaseaction.save(user);
            System.out.println(user);

            System.out.println(user.getFname());
            System.out.println(user.getLname());
            System.out.println(user.getEmail());
            System.out.println(user.getMobNo());
            System.out.println(user.getAddress());

        } catch (Exception e) {
            System.out.println("");
        }
        return mv;
    }

}

Model class :

package com.example.demo3.model;

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

@Entity
public class usermodel {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int ID;
    private String Fname;
    private String Lname;
    private String Email;
    private String MobNo;
    private String Address;
    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    public String getFname() {
        return Fname;
    }
    public void setFname(String fname) {
        Fname = fname;
    }
    public String getLname() {
        return Lname;
    }
    public void setLname(String lname) {
        Lname = lname;
    }
    public String getEmail() {
        return Email;
    }
    public void setEmail(String email) {
        Email = email;
    }
    public String getMobNo() {
        return MobNo;
    }
    public void setMobNo(String mobNo) {
        MobNo = mobNo;
    }
    public String getAddress() {
        return Address;
    }
    public void setAddress(String address) {
        Address = address;
    }

}

Repository interface : (here i've tried @Repository,@Service,@Component everything)

package com.example.demo3.repository;


import org.springframework.data.repository.CrudRepository;

import com.example.demo3.model.usermodel;

public interface Databaseaction extends CrudRepository<usermodel, Integer> {

}

application.properties :

spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/learningspring
spring.datasource.username=root
spring.datasource.password=""
PaulNUK
  • 4,774
  • 2
  • 30
  • 58
  • Welcome to StackOverflow! Your question needs some work so the community can better help you. Take a look at [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and give it another try. – Chris Albert Mar 26 '19 at 13:03
  • I think you have a similar issue to this: [ [bean named 'entityManagerFactory' could not be found]] take a look. [bean named 'entityManagerFactory' could not be found]: https://stackoverflow.com/questions/53923909/bean-named-entitymanagerfactory-could-not-be-found – Jihana Mar 26 '19 at 13:50
  • Multiple code formatting changes, corrections to make the text more readable, grammar and spelling fixes – PaulNUK Mar 26 '19 at 15:16
  • Looks like you're on the right track and you got pretty far already. Can you tell us which dependencies you have? – g00glen00b Mar 27 '19 at 07:13
  • org.springframework.bootspring-boot-starter-data-jpaorg.springframework.bootspring-boot-starter-web,mysql mysql-connector-java,org.springframework.bootspring-boot-starter-tomcatprovided,org.springframework.bootspring-boot-starter-testtest,org.apache.tomcattomcat-jasper9.0.16 – Aaravind Mar 28 '19 at 04:40
  • these are the dependencies i've used – Aaravind Mar 28 '19 at 04:45

0 Answers0