Skip to content

Instantly share code, notes, and snippets.

@enujo
Created January 6, 2017 07:08
Show Gist options
  • Save enujo/ab7c032eb8ce7e3a765c249f39e98cd9 to your computer and use it in GitHub Desktop.
Save enujo/ab7c032eb8ce7e3a765c249f39e98cd9 to your computer and use it in GitHub Desktop.
spring mvc insert
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<context:component-scan base-package="com.tistory.luahius" />
<!--1) dataSource 객체를 생성 connection의 arrayList가 된다 하지만 우리는 mybatis가 할것 이니까 이건 mybatis가 가지면 된다 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> <!-- 프로퍼티란 주입, setter -->
<property name="url" value="jdbc:mysql://127.0.0.1:3306/jjdev"/>
<property name="username" value="root"/>
<property name="password" value="java0000"/>
</bean>
<!--2) mybatis 세션생성을 위한 팩토리 생성 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- mybatis 세션생성시 사용할 dataSource주입 ref : 참조타입이 들어오는 것-->
<property name="dataSource" ref="dataSource" />
<!-- mybatis 세션생성후 쿼리를 실행시킬때 사용할 쿼리위치(메퍼)설정 dao가 있는 곳에-->
<property name="mapperLocations">
<list>
<value>classpath:com/tistory/luahius/service/BoardMapper.xml</value>
</list>
</property>
</bean>
<!--3) mybatis를 사용하여 db에접속하여 쿼리를 보내는 주체인 SqlSessionTemplate빈 생성-->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" /> <!-- 생성자의 첫번째의 매개변수로 주입된다 -->
</bean>
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment