๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Spring

[Spring] Spring ์—๋Ÿฌ / Error creating bean with name 'sqlSessionFactory' defined in class path resource

by JulesJ 2021. 11. 11.
728x90

SpringToolSuite4๋ฅผ ์ด์šฉํ•ด SpringBoot project๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‹คํ–‰ํ•˜๋ฉด์„œ

์ดˆ๊ธฐ์— ๋‹ค์Œ๊ณผ ๊ฐ™์€ SpringBoot ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

 

(sqlSessionFactory ์˜ค๋ฅ˜)

Error creating bean with name 'sqlSessionFactory' defined in class path resource 

 

- ํ•„์ž์˜ ๊ฒฝ์šฐ ์˜ค๋ฅ˜๋Š” mybatis/mapper.xml์„ ์ฐพ์ง€ ๋ชปํ•˜๋Š” ์˜ค๋ฅ˜๋กœ, property value์˜ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜์ •ํ•˜๋ฉฐ ํ•ด๊ฒฐํ–ˆ๋‹ค.

DatabaseConfiguration.java ํŒŒ์ผ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

mybatis ํด๋” ๊ฒฝ๋กœ๋ฅผ ์ž˜ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค.

ํด๋”๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์—๋„ ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค.

  @Bean
  public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception{
      SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
      sqlSessionFactoryBean.setDataSource(dataSource);
      sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources("classpath:/mybatis/**/*.xml"));   
      return sqlSessionFactoryBean.getObject();
  }

 

์˜คํƒ€์กฐ์‹ฌ

๋Œ“๊ธ€