basic/spring

spring

못지(Motji) 2023. 9. 11. 13:10

spring 파일 import 했을 때 세팅

 

web.xml 

servlet

<!-- 요클래스를 이런이름으로 부를거다. 클라이언트는 어떻게 호출할수 있는지. 스프링으로 들어가려면 .htm으로 가능
  가상의 확장자를 만듬. 해당 확장자의 파일이 존재하면 안됨. ->

 

<context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  
  <listener>
  	
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  스프링세팅 담당
  listener는 필수.
  스프링 내부에서는 내가 관리할거임. 스프링 안에서 context를 관리하는것

 

applicationContext.xml

 

<?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:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
	<!-- 여기까지가 new - other - Spring - Spring Bean Configuration File 로 생성하고 설정한 정보-->


	
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
		<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ORCL" />
		<property name="username" value="scott"/>
		<property name="password" value="tiger" />
	</bean>
	
	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="configLocation" value="WEB-INF/sqlmap-config.xml" />
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
		<property name="sqlMapClient" ref="sqlMapClient" />
	</bean>
    sqlMapClient 라는 이름으로 sqlMapClient를 가져다가 쓰겠다.
	
	<bean id="boardDAO" class="kr.co.mycom.board.model.BoardDAOImpl">
		<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" />
	</bean>
    내부적으로 sqlMapClientTemplate를 가지고 있겠다.
	
	<bean id="boardService" class="kr.co.mycom.board.Service.BoardServiceImpl">
		<property name="boardDAO" ref="boardDAO"></property>
	</bean>
    service에서 boardDAO를 씀
	
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
    트랜잭션 관리는 dbdbdbdb만
	
    DTO는 컨트롤러에서 쓸거라서 여기에 등록 안해도됨.
    원래는 컨트롤러랑 뷰도 여기에 써놔야함.
    벗 우리는 자동화해놨기 때문에 안써놔도 됨><
    
	
	
</beans>



<bean id="boardDAO" class="kr.co.mycom.board.model.BoardDAOImpl">
		<property name="sqlMapClientTemplate" ref="sqlMapClientTemplate" />
	</bean>
	
	<bean id="boardService" class="kr.co.mycom.board.Service.BoardServiceImpl">
		<property name="boardDAO" ref="boardDAO"></property>
	</bean>
    
    요것만 나중에 추가하면됨

 

spring-servlet

<?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:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


	<!-- 컨트롤등록 : 자동으로 컨트롤러를 찾는다. -->
	<context:component-scan base-package="kr.co.mycom.board.controller" />
	
	<bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
    	<property name="prefix" value="/WEB-INF/view/"/>
    	<property name="suffix" value=".jsp"/>
    </bean>
    컨트롤러 뷰 = 프론트단이라 파일 나눠서 관리
    InternalResourceViewResolver를 통해서 auto 리졸브
    컨트롤러가 리턴만 해주면 그리턴하는 값에 prefix suffix 앞에 뒤에 붙인다.
    jsp이름만 리턴해주면
    
    WEB-INF : URL로는 다이렉트로 못들어가는 폴더. 안보여줌~.~
    
    
</beans>

sqlmap-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC 
	"-//iBATIS.com//DTD SQL Map Config 2.0//EN"
	"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>

	<sqlMap resource="kr/co/mycom/board/model/Board.xml"/>
		
</sqlMapConfig>



sql을 저장하는 xml을 저장
dao 등록 applicationcontext에 등록