반응형






첫 번째 파일 : web.xml (WEB-INF폴더)

--  WEB-INF 폴더에 'config'란 폴더 생성 후 'presentation-layerbiz.xml' 파일 생성

--  서버 시작될 때, 해당 위치에 있는 context파일을 모조리 읽어들이는 것을 뜻합니다.

     이 경로 안에 파일이 오류나면 서버 실행시 404 에러가 발생합니다.

--  중간의 characterEncoding 은 한글 인코딩을 위해 사용합니다.

--  servlet-name. class, url-pattern 에 오타 없는지 꼭 확인 해야 합니다.

     이 부분은 컨트롤러를 위해 사용 됩니다.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!--?xml version="1.0" encoding="UTF-8"?-->
 
    <!-- localhost:8080/프로젝트명 으로 접속시 여기 경로로 접속됨 -->
    <welcome-file-list>
        <welcome-file>ex(main.do or index.jsp)</welcome-file>
    </welcome-file-list>   
 
 
 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
     
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <!-- 한글 입력때문에 하는것 -->
    <filter>
        <filter-name>characterEncoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncoding</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
 
 
    <!--  servlet-name. class, url-pattern 에 오타 없는지 확인 해야함
        이는 최소 서버가 시작될 때, 해당 위치에 있는 context파일을 모조리 읽어들이는 것을 의미함
        컨트롤러를 위해서 쓰는 놈들임
     -->
    <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <!-- <param-value>/WEB-INF/config/servlet-context.xml</param-value> -->
            <param-value>/WEB-INF/config/presentation-layerbiz.xml</param-value>
        </init-param>
    </servlet>
         
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
 
</web-app>




두 번째 파일 : root-context.xml(WEB-INF -> spring 폴더)

--  DB를 연동 할 때 사용함. 중간중간 DB 및 서버 정보는 사용자에 맞게 입력해야합니다.

--  3 번째 단락의 component-scan은 Service 와 Implement 가 저장된 패키지명으로 해야됩니다.


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
31
32
33
<!--?xml version="1.0" encoding="UTF-8"?-->
        http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.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-4.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd">
     
   <!-- 1. 데이터 베이스 연결 -->
   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <!-- <property name="driverClassName" value="ex(org.mariadb.jdbc.Driver)" /> -->
      <property name="driverClassName" value="ex(com.mysql.jdbc.Driver)">
      <property name="url" value="ex(jdbc:mysql://서버포트번호/db이름?serverTimezone=UTC)">
      <property name="username" value="ex(ID)">
      <property name="password" value="ex(PW)">
   </property></property></property></property></bean>
 
   <!-- 2.SqlSessionFactory(파일 없으면 404에러뜸) -->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
      <property name="dataSource" ref="dataSource"></property>
      <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
      <property name="mapperLocations" value="classpath:/mappers/*Mapper.xml"></property>
   </bean>
 
   <!-- 3. SqlSessionTemplate DB연결 & 종료 -->
   <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="ex(mybatisUtil)"></context:component-scan>
 
   <!-- Root Context: defines shared resources visible to all other web components -->
</beans>




세 번째 파일 : presentation-layerbix.xml

--  component-scan 의 base-package 부분은 controller 를 저장한 패키지 이름으로 해야합니다.


1
2
3
4
5
6
7
8
9
10
11
<!--?xml version="1.0" encoding="UTF-8"?-->
   
    <context:component-scan base-package="컨트롤러 패키지이름(ex:controller)"></context:component-scan>
   <!-- ViewResolver 등록 -->
   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/"></property>
      <property name="suffix" value=".jsp"></property>  
   </bean>
</beans>




반응형

+ Recent posts