创建名称为“ frontcontroller”的bean时出错:通过字段“ databaseaction”表达的不满意的依赖性

时间:2019-03-26 12:52:58

标签: spring-boot spring-data-jpa

此刻我正在学习Spring Boot。我正在尝试使用Spring Data Jpa在mysql表中插入一些数据。当我尝试创建自动装配库界面时,在运行应用程序时遇到此问题。

我在ReflectionUtils类中遇到此错误:

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

在我的控制台中,我收到此错误:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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.

如何纠正此问题。我正在使用IDE STS-4

源代码:

控制器类:

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;
    }

}

模型类:

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,@ Service,@ Component一切)

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=""

0 个答案:

没有答案