dldldl
162
2020-04-17 10:49:15
0
163

spring boot mybatis dataSource 연동 오류


application.properties

spring.db1.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.db1.datasource.url=jdbc:sqlserver://;databasename=
spring.db1.datasource.username=
spring.db1.datasource.password=


db1DatabaseConfig


@Configuration
@MapperScan(value = "com.swit.app.mapper", sqlSessionFactoryRef = "db1SqlSessionFactory")
@EnableTransactionManagement
public class Db1DatabaseConfig {

	@Bean(name = "db1DataSource")

	@ConfigurationProperties(prefix = "spring.db1.datasource")
	public DataSource db1DataSource() {
		return DataSourceBuilder.create().build();
	}

	@Bean(name = "db1SqlSessionFactory")

	public SqlSessionFactory db1SqlSessionFactory(@Qualifier("db1DataSource") DataSource db1DataSource, ApplicationContext applicationContext)
			throws Exception {

		SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

		sqlSessionFactoryBean.setDataSource(db1DataSource);
		sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources("mybatis/mappers/**/*.xml"));

		return sqlSessionFactoryBean.getObject();
	}

	@Bean(name = "db1SqlSessionTemplate")

	public SqlSessionTemplate db1SqlSessionTemplate(SqlSessionFactory db1SqlSessionFactory) throws Exception {
		return new SqlSessionTemplate(db1SqlSessionFactory);
	}

}


LoginController

@RestController
public class LoginController {
	@Autowired
	private LoginService loginService;

	@ResponseBody
	@RequestMapping("/new")
	public String root_test() throws Exception {
		return "Hello World";
	}

	@ResponseBody
	@RequestMapping("/db1")
	public List<LoginVO> db1() throws Exception {
		List<LoginVO> list = loginService.getList();
		System.out.println("WOWWOWWOWWOW");
		System.out.println(list);

		return loginService.getList();
	}


LoginService

@Service
public class LoginService {

	@Autowired
	private LoginMapper mapper;

	public List<LoginVO> getList() throws Exception {
		return mapper.getList();
	}
}


LoginMapper

@Repository
@Mapper
public interface LoginMapper {
	List<LoginVO> getList() throws Exception;
}


LoginMapper.xml

<mapper namespace="com.swit.app.mapper.LoginMapper">

	<select id="getList"  resultType="com.swit.app.vo.LoginVO" statementType="PREPARED">
		SELECT * FROM TB_SWIT_LOGIN
	</select>
	
</mapper>


이렇게하고 실행시키면 아래와 같은 오류가 뜹니다ㅠㅠ 왜그러는걸까요



해결법 알려주세요ㅠㅠ 급합니다

0
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.