application.yaml
spring:
datasource:
driver-class-name: org.mariadb.jdbc.Driver
url: "jdbc:mariadb://localhost:3306/<Database 이름>?characterEncoding=UTF-8&serverTimezone=UTC"
username:
password:
ConnectionTest.java
@SpringBootTest
//SpringBootTest 는 실제 애플리케이션을 자신의 로컬 위에 올려서 포트 주소가 Listening 되어지고, 실제 Database 와 커넥션이 붙어지는
//상태에서 진행되는 Live 테스트 방법
public class ConnectionTest {
@Autowired
private DataSource dataSource;
@Test
public void connectionTest() throws SQLException {
Connection con = dataSource.getConnection();
System.out.println(con);
}
}
AppConfig.java
@Configuration
@ComponentScan
public class SpringConfig{
private final DataSource dataSource;
public SpringConfig(DataSource dataSource){
this.dataSource = dataSource;
}
}
아래와 같이 @EnableAutoConfiguration 어노테이션을 적용하면 된다
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class GetTeamApplication {
public static void main(String[] args) {
SpringApplication.run(GetTeamApplication.class, args);
}
}