Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

고마구의 개발 블로그

240717 spring jdbc 4가지 넣을거 본문

KDT풀스택과정 공부

240717 spring jdbc 4가지 넣을거

고마구 2024. 7. 17. 10:53

pom.xml 스프링 위에 붙여넣기

<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>21.5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.3.5.RELEASE</version>
</dependency>

 

 

서블릿-콘텍스트xml

<context:component-scan base-package="com.human.service" />

추가

 

루트 콘텍스트에 추가

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

<!-- Root Context: defines shared resources visible to all other web components -->

<bean 
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
 name="dataSource">
   <property value="oracle.jdbc.driver.OracleDriver" name="driverClassName"/>
   <property value="jdbc:oracle:thin:@localhost:1521:xe" name="url"/>
   <property value="c##human" name="username"/>
   <property value="human" name="password"/>
 </bean>
 

<bean id="sqlSessionFactory" 
      class="org.mybatis.spring.SqlSessionFactoryBean">
      
  <property name="dataSource" ref="dataSource" />
<property name="configLocation" 
value="classpath:/mybatis-config.xml"></property>
<property name="mapperLocations" 
      value="classpath:mappers/**/*Mapper.xml"></property>
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" 
   destroy-method="clearCache">
  <constructor-arg name="sqlSessionFactory" 
    ref="sqlSessionFactory"></constructor-arg>
</bean>
<context:component-scan base-package="com.human.service" />
</beans>