第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

通過字段 'employeeDao' 表達(dá)的不滿足依賴;

通過字段 'employeeDao' 表達(dá)的不滿足依賴;

神不在的星期二 2023-02-23 16:54:57
I am fresh to spring boot and currently facing this error in STS"Error creating bean with name 'employeeDao': Unsatisfied dependency expressed through field 'sessionfactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException"Entity Class@Entity@Table(name = "studenttable")public class Employee {@Id    @GeneratedValue(strategy=GenerationType.AUTO)    private Long id;    @Column(name = "sname")    private String sname;    @Column(name = "scourse")    private String cname;    @Column(name = "sfee")    private Double fee;Hibernate Utils Class    @Configuration    public class HibernateUtilsConfig {        @Autowired        private EntityManagerFactory entityManagerFactory;        @Bean        public SessionFactory getSessionFactoty() {            if(entityManagerFactory.unwrap(SessionFactory.class)== null) {                throw new NullPointerException("Factory Not Found");            }            return entityManagerFactory.unwrap(SessionFactory.class);        }DAO Class@Repositorypublic class EmployeeDao {    @Autowired    private SessionFactory sessionfactory;    public void createEmployee(Employee employee) {        Session session = null;        try {            session = sessionfactory.openSession();            session.beginTransaction();        Integer id=(Integer)    session.save(employee);        System.out.println("The record is add in the system" + id);            session.getTransaction().commit();        }catch (Exception e) {            // TODO: handle exception            e.printStackTrace();        }    }Main Class@SpringBootApplicationpublic class SpringExampleApplication implements CommandLineRunner {    @Autowired    private EmployeeDao employeeDao;    public static void main(String[] args) {        SpringApplication.run(SpringExampleApplication.class, args);    }
查看完整描述

1 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

您面臨的問題是由于HibernateUtilsConfig.java您提供的配置類引起的。在您的 EmployeeDao 類中,您正在自動(dòng)裝配sessionfactorybean。因此,當(dāng) springboot 嘗試自動(dòng)裝配 bean 時(shí),它會(huì)失敗并出現(xiàn)以下錯(cuò)誤:


Unsatisfied dependency expressed through field 'sessionfactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hibernateUtilsConfig': Unsatisfied dependency expressed through field 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'getSessionFactoty': Requested bean is currently in creation: Is there an unresolvable circular reference?

因?yàn)閑ntityManagerFactorybean 不可用。


由于您使用的是 spring-boot ,因此您可能無法手動(dòng)配置所有內(nèi)容。您可以通過添加以下依賴項(xiàng)來使用 spring-boot 的默認(rèn)自動(dòng)配置:


<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

然后,您可以在 application.properties 或 application.yml 中提供適當(dāng)?shù)逆I,spring-boot 將為您配置所有內(nèi)容。


application.properties


spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.username=mysqluser

spring.datasource.password=mysqlpass

spring.datasource.url=jdbc:mysql://localhost:3306myDb?createDatabaseIfNotExist=true

如果您仍想手動(dòng)設(shè)置所有內(nèi)容,請(qǐng)嘗試創(chuàng)建實(shí)體管理器 bean,例如:


   @Bean

   public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

      LocalContainerEntityManagerFactoryBean em 

        = new LocalContainerEntityManagerFactoryBean();

      em.setDataSource(dataSource());

      em.setPackagesToScan(new String[] { "com.example.persistence.model" });


      JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

      em.setJpaVendorAdapter(vendorAdapter);

      em.setJpaProperties(additionalProperties());


      return em;

   }


查看完整回答
反對(duì) 回復(fù) 2023-02-23
  • 1 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)