Spring/Spring 공부

[spring] 프로젝트 설정 0-3. root-context.xml 설정

congs 2023. 6. 2. 15:14

 

1. Namespace에 사용하는 부분 체크

  • 여기에 뜨는 것들은 https://jungeun980906.tistory.com/354 (pom.xml)에 라이브러리를 넣은 것들임!
  • 만약 필요한 부분이 뜨지 않는다면, pom.xml을 확인해보기!
  • aop, context, jdbc, mybatis 추가 체크하고 저장!


source에 추가되어 있는 것을 확인이 가능!

 


 

- 추후에 추가 예정 : pom.xml에 추가하고 root-context.xml에서 체크

https://mvnrepository.com/artifact/org.springframework/spring-test

 


 

2. Source에 DB 설정

 

spring_project에서 사용할 DB와 user 미리 정해놓기!

DB : springtest
user : springuser
password : mysql

 

<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
	xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
		http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
		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
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
	
	<!-- Root Context: defines shared resources visible to all other web components -->
	<bean id="dataSource" 
	class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
		<property name="url" value="jdbc:mysql://localhost:3306/springtest"></property>
		<property name="username" value="springuser"></property>
		<property name="password" value="mysql"></property>
	</bean>
	<bean id="sqlSessionFactory" 
	class="org.mybatis.spring.SqlSessionFactoryBean">
	<property name="dataSource" ref="dataSource"></property>
	<property name="mapperLocations" value="classpath:mappers/**/*Mapper.xml"></property>
	<!-- /**/의 의미는 폴더안의 어떤 폴더안의 폴더로 들어갈 경우 대비한 설정 -->
	</bean>
	<mybatis-spring:scan base-package="com.myweb.www.repository"/>
	<!-- src/main/java안의 패키지이름.repository 넣기  -->
		
</beans>

 


여기까지 생성하면 출력화면