[springboot] oracle 연결+API
environment: #springboot #maven #oracle #eclipse(sts) #java
- spring starter project 생성
-
File-New-Other-Spring Starter Project
-
Name: API, Type: Maven, Packaging: Jar, Java Version: 8, Language: Java, Group: com.api, Package: com.api
-
Dependency(의존성): JDBC API, Oracle Driver, Spring Web
- spring boot 실행
- pom.xml 확인
(spring web 미선택시 실행하자마자 중단됨)
참고: https://stackoverflow.com/questions/22380119/why-does-my-spring-boot-app-always-shutdown-immediately-after-starting
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
** <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>**
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
- 프로젝트 우클릭-Run As-Spring Boot App
- localhost:8080 접속
- API(db없이 springboot 단독)
참고: https://www.youtube.com/watch?v=PExqR3Pt1LM&list=PL2MM0GtSmRHnEFFsX5UL6iSBgH7PA23UC&index=3
- API\src\main\java\com\API\Controller\TestController 생성
package com.db.Controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping(value="/test")
public Map<String,Object> test() {
Map<String,Object> result = new HashMap<String,Object>();
result.put("name", "happy");
result.put("age", 10);
return result;
}
}
@RestController
, @RequestMapping
: ctrl+space, enter
HashMap
: ctrl+shift+o
2. 실행
3. localhost:8080/test 접속
- springboot-oracle 연결
참고: https://www.youtube.com/watch?v=PExqR3Pt1LM&list=PL2MM0GtSmRHnEFFsX5UL6iSBgH7PA23UC&index=3
- oracle-table 생성
create table test(
id int primary key,
name varchar(20),
email varchar(20)
);
insert into test(id, name, email)
values(1,'happy','[email protected]');
select * from test;
- application.properties 수정
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/orcl
spring.datasource.username=system
spring.datasource.password=1234
- pom.xml 수정
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
api/controller/TestController
,api/dao/TestDao
,api/service/TestService
- 실행
- localhost:8080/getList 접속
Author And Source
이 문제에 관하여([springboot] oracle 연결+API), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@happpyminsu/extjs-springboot-oracle저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)