Maven+oracle+SSM 간단 한 프로젝트 만 드 는 방법

25712 단어 MavenOacleSSM세우다
Maven 구축 ssm 프로젝트 에 대해 간단히 말씀 드 리 겠 습 니 다.
maven 의 웹 프로젝트 를 만 들 때 main/자바,main/test 두 개의 폴 더 가 부족 합 니 다.
해결 방법:
①:프로젝트 에서 properties 를 오른쪽 단추 로 선택 한 후 자바 build path 를 클릭 하고 Librarys 에서 JRE System Library 를 편집 하고 Workspace default jre 를 선택 하면 된다.(이런 걸 추천 합 니 다)
②:디 렉 터 리 를 수 동 으로 만 듭 니 다.보 기 를 전환 하려 면 Navigator 보 기 를 사용 하여 src/main 디 렉 터 리 에 자바 디 렉 터 리 를 직접 만 듭 니 다.
프로젝트 디 렉 터 리 구조:

중요 한 프로필:
대상 모델 프로필:pom.xml
Spring 설정 파일:applicationContext.xml
spring MVC 프로필:springmvc.xml
데이터베이스 프로필:jdbc.properties
로그 프로필:log4j.properties
mybatis 프로필:mybatis-config.xml
네트워크 프로그램 프로필:웹.xml
우선 pom.xml 설정
pom.xml 는 주로 프로젝트 의 maven 좌 표를 설명 하고 의존 관 계 를 설명 하 며 jar 가방 을 자동 으로 도입 합 니 다.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.krry</groupId>
 <artifactId>maven_SSM</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>maven_SSM</name>
 <url>http://maven.apache.org</url>

 <dependencies>
  <!--  junit -->
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.11</version>
   <scope>test</scope>
  </dependency>
  <!--  servlet -->
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>servlet-api</artifactId>
   <version>3.0-alpha-1</version>
   <scope>provided</scope>
  </dependency>
  <!--  jstl   -->
  <dependency>
   <groupId>jstl</groupId>
   <artifactId>jstl</artifactId>
   <version>1.2</version>
   <scope>provided</scope>
   </dependency>
   
   <!--  jsp      -->
   <dependency>
   <groupId>javax.servlet.jsp</groupId>
   <artifactId>jsp-api</artifactId>
   <version>2.2</version>
   <scope>provided</scope>
   </dependency>
   
   <!--  log4j -->
   <dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.17</version>
   </dependency>
   
   <!--spring springmvc mybatis -->
   <!-- spring springmvc      jar --> 
   <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>4.2.1.RELEASE</version>
   </dependency>
   
   <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
   <version>4.2.1.RELEASE</version>
   </dependency>
    
   <!-- springmvc   -->
   <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>4.2.1.RELEASE</version>
   </dependency>
   
   <!--springmvc    json     jackson -->
   <dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-core</artifactId>
   <version>2.5.4</version>
   </dependency>
   
   <dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-annotations</artifactId>
   <version>2.5.4</version>
   </dependency>
   
   <dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-databind</artifactId>
   <version>2.5.4</version>
   </dependency>
   
   <!--JSR303      hibernate validator -->  
   <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-validator</artifactId>
   <version>5.1.1.Final</version>
   </dependency>
   
   <!--       jar  -->
   <dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>2.4</version>
   </dependency>
   
   <dependency>
   <groupId>commons-fileupload</groupId>
   <artifactId>commons-fileupload</artifactId>
   <version>1.3.1</version>
   </dependency>
   
   <dependency>
   <groupId>org.apache.commons</groupId>
   <artifactId>commons-lang3</artifactId>
   <version>3.3.2</version>
   </dependency>
   
   <!--        codeC -->
  <dependency>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
   <version>1.9</version>
  </dependency>
   
   <!--orm  jdbc       jar  mybatis -->
  <!--oracle      -->
  <dependency>
   <groupId>com.oracle</groupId> 
   <artifactId>ojdbc6</artifactId> 
   <version>12.1.0.2.0</version>
  </dependency>
  <!--mysql      (    ,      oracle  ) -->
  <!-- 
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>5.0.8</version>
   <scope>runtime</scope>
  </dependency>
  -->
  
  <!-- proxool    -->
  <dependency>
   <groupId>com.cloudhopper.proxool</groupId>
   <artifactId>proxool</artifactId>
   <version>0.9.1</version>
  </dependency>
  <dependency>
   <groupId>com.cloudhopper.proxool</groupId>
   <artifactId>proxool-cglib</artifactId>
   <version>0.9.1</version>
  </dependency>


   <!--  mybatis   jar  -->
   <dependency>
   <groupId>org.mybatis</groupId>
   <artifactId>mybatis</artifactId>
   <version>3.3.1</version>
  </dependency>
  
  <dependency>
   <groupId>org.mybatis</groupId>
   <artifactId>mybatis-spring</artifactId>
   <version>1.2.4</version>
  </dependency>
  
  <!--        jar ,      -->
  <dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper</artifactId>
   <version>4.2.1</version>
  </dependency>
  
 </dependencies>
 <build>
  <plugins> 
   <plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
     <source>1.7</source> 
     <target>1.7</target> 
    </configuration> 
   </plugin> 
   <plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.4</version> 
    <configuration> 
     <version>3.0</version> 
    </configuration> 
   </plugin> 
  </plugins> 
  <finalName>maven_SSM</finalName> 
 </build> 
</project>
maven 프로젝트 가 pom.xml 를 이용 하여 Oacle 드라이브 백 을 가 져 오 는 문 제 를 말씀 드 리 겠 습 니 다.
Oracle 권한 수여 문제 로 인해 Maven 은 Oracle JDBC driver 를 제공 하지 않 으 며 Maven 프로젝트 에 Oracle JDBC driver 를 적용 하기 위해 서 는 로 컬 창고 에 수 동 으로 추가 해 야 합 니 다.
컴퓨터 에 Oracle 데이터베이스 가 설치 되 어 있 으 면 설치 경로 에 데이터베이스 드라이버 가 있어 직접 사용 할 수 있다.D:\Oracle\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib
Oracle 홈 페이지 에서 Oracle 데이터베이스 드라이버 를 직접 다운로드 하고 SQL 문 구 를 사용 하여 데이터베이스 드라이버 버 전 을 조회 할 수 있 습 니 다:SELECT*FROM v$instance
그리고 버 전 다운로드 확인:
windows 명령 행 인터페이스 를 열 고 드라이버 ojdbc 6 디 렉 터 리 에 들 어가 서 실행 합 니 다.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=12.1.0.2.0 -Dpackaging=jar -Dfile=ojdbc6.jar
"BUILD SUCCESS"가 성공 하면 마 븐 로 컬 창 고 를 자동 으로 가 져 옵 니 다.
그리고 Maven 프로젝트 에 dependency 를 추가 할 수 있 습 니 다.각 좌 표 는 위의 명령 에 대응 하 는 요 소 를 다음 과 같 습 니 다.

 <dependency>  
  <groupId>com.oracle</groupId>  
  <artifactId>ojdbc6</artifactId>  
  <version>12.1.0.2.0</version>
 </dependency> 
Spring 설정 파일: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:tx="http://www.springframework.org/schema/tx"
 xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans.xsd 
 http://www.springframework.org/schema/aop 
 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx-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/util 
 http://www.springframework.org/schema/util/spring-util-3.0.xsd
 ">

 <!--       -->
 <context:component-scan base-package="com.krry"></context:component-scan>
  
 <!--          -->
 <!-- <context:property-placeholder location="classpath:jdbc.properties" /> -->
 <bean class="com.krry.core.des.EncryptPropertyPlaceholderConfigurer"
  p:location="classpath:jdbc.properties" p:fileEncoding="utf-8" />
  
 <!-- proxool    -->
 <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
  <!--      ,mysql -->
  <property name="driver" value="${db.driver}"></property>
  <!--proxool   url   ,             -->
  <property name="driverUrl" value="${db.url}"></property>
  <!--    (proxool    ,      ) -->
  <property name="user" value="${db.username}"></property>
  <!--   (proxool    ,      ) -->
  <property name="password" value="${db.password}"></property>
  <!-- proxool               (  ),             ,           4 ) -->
  <property name="houseKeepingSleepTime" value="3000"></property><!--              -->
  <property name="testBeforeUse" value="true"></property>
  <!--              .house keeper           .             .      ,          -->
  <property name="houseKeepingTestSql" value="SELECT count(1) from dual"></property>
  <!--   housekeeper                   .         .              .         .   5  .      10  --> 
  <property name="maximumActiveTime" value="10000"></property>
  <!--            (    20 ) -->
  <property name="prototypeCount" value="20"></property>
  <!--       (    100 ) -->
  <property name="maximumConnectionCount" value="200"></property>
  <!--       (    50 ) -->
  <property name="minimumConnectionCount" value="50"></property>
  <!--    true,        SQL         log  (DEBUG LEVEL).        ConnectionListener (  ProxoolFacade)      . -->
  <property name="trace" value="false"></property>
  <property name="verbose" value="true"></property>
 </bean>
 
 <!--         -->
 <bean id="txMgr"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"></property>
 </bean>

 <!--          -->
 <tx:annotation-driven transaction-manager="txMgr" />
 
 <!--   mybatis sqlSessionFactory -->
 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <property name="configLocation" value="classpath:mybatis-config.xml"></property>
 </bean>
 
 <!--         Mapper       -->
 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  <!--        ,        -->
  <property name="basePackage" value="com.krry.mapper"></property>
  <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
 </bean> 
</beans>
spring MVC 프로필:springmvc.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:p="http://www.springframework.org/schema/p"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:util="http://www.springframework.org/schema/util" 
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-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/util 
  http://www.springframework.org/schema/util/spring-util-3.0.xsd 
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc.xsd
  ">
   <!--          --> 
  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 
  <!--   mvc      user       ConversionService   FormattingConversionServiceFactoryBean-->
   <mvc:annotation-driven>
   <mvc:message-converters register-defaults="true">
    <bean class="com.krry.core.UTF8StringHttpMessageConverter">
     <property name="supportedMediaTypes">
      <list> 
       <value>text/plain;charset=UTF-8</value> 
       <value>text/html;charset=UTF-8</value> 
      </list> 
     </property>
    </bean> 
    <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
    <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> 
    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
     <property name="prefixJson" value="false" />
     <property name="objectMapper">
       <bean class="com.fasterxml.jackson.databind.ObjectMapper">
        <!--   responseBody        --> 
        <property name="dateFormat"> 
         <bean class="java.text.SimpleDateFormat"> 
          <constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" /> 
         </bean> 
        </property> 
        <!--  null       -->
        <property name="serializationInclusion">
         <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
        </property> 
       </bean> 
     </property>
      <property name="supportedMediaTypes"> 
      <list> 
       <value>application/json;charset=UTF-8</value> 
       <value>application/x-www-form-urlencoded;charset=UTF-8</value> 
      </list> 
     </property>
    </bean>
    </mvc:message-converters> 
  </mvc:annotation-driven>
  
   <!--    -->
   <context:component-scan base-package="com.krry.controller"></context:component-scan>
   
   <!--                ,   springmvc       /      ,
          (.do ,addUser,js/image/css)   springmvc  ,
                     -->
  <!--             -->
  <!--<mvc:default-servlet-handler/> -->
  <mvc:resources mapping="/resourse/**" location="/resourse/" />
  
  <!--       -->
  <mvc:interceptors> 
   <mvc:interceptor>
    <!--            admin           -->
    <mvc:mapping path="/admin/**"></mvc:mapping> 
     <!--                 -->
     <mvc:exclude-mapping path="/resourse/**"/>
   <!--        ,  false            -->
   <bean class="com.krry.core.filter.LoginInterceptor" />  
   </mvc:interceptor>
  </mvc:interceptors>
  
   <!--         -->
  <bean id="multipartResolver"
   class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
   p:defaultEncoding="utf-8">
   <property name="uploadTempDir" value="/temp"></property>
   <property name="maxUploadSize">
    <value>209715200</value><!-- 200MB -->
   </property>
   <property name="maxInMemorySize">
    <value>4096</value><!-- 4KB     -->
   </property>
  </bean>
   
 
  <!--      jsp/freemaker/velocity-->
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!--           -->
    <property name="prefix" value="/WEB-INF/pages/"></property>
    <!--       -->
    <property name="suffix" value=".jsp"></property>
  </bean>  
</beans>
데이터베이스 프로필:jdbc.properties

 db.driver=oracle.jdbc.OracleDriver
 db.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
 db.username=4m+la23KCA4=
 db.password=WWijcIyMPaU\=

암호 화 알고리즘 을 사 용 했 습 니 다.
로그 프로필:log4j.properties

log4j.rootLogger=DEBUG, CONSOLE, FILE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %10l - %m%n

log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=D:/logs/log4j.log
log4j.appender.FILE.MaxFileSize=1MB
log4j.appender.FILE.Append = true
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy/MM/dd/HH:mm:ss} %-5p [%t] %10l - %m%n
mybatis 프로필:mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE configuration 
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-config.dtd"> 

<configuration> 
 <settings> 
   <!--           --> 
  <setting name="cacheEnabled" value="true" /> 
   <!--    ,                --> 
  <setting name="lazyLoadingEnabled" value="true" /> 
  <!--            ,         (     SQL      ),            ,      --> 
  <setting name="aggressiveLazyLoading" value="false" /> 
  <!--      SQL  ,                   --> 
  <setting name="multipleResultSetsEnabled" value="true" /> 
  <!--             --> 
  <setting name="useColumnLabel" value="true" /> 
  <!--            (        UUID 32       ),    PK         --> 
  <setting name="useGeneratedKeys" value="true" /> 
   <!--       resultMap   -        --> 
  <setting name="autoMappingBehavior" value="FULL" /> 
  <!--           SQL      --> 
  <setting name="defaultExecutorType" value="BATCH" /> 
   <!--      25000         --> 
  <setting name="defaultStatementTimeout" value="25" /> 
   <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
 </settings> 
 
 <typeAliases>
  <!--   user      -->
  <!-- <typeAlias type="com.krry.mybatis.sysmanage.entity.User" alias="user"/> -->
  <!--        -->
  <package name="com.krry.entity" />
 </typeAliases> 
</configuration>
네트워크 프로그램 프로필:웹.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 
 <display-name>maven_SSM</display-name>
 
 <welcome-file-list>
 <welcome-file>index</welcome-file>
 </welcome-file-list>
 
 <!--   Spring IOC   -->
 <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 
 <!-- spring       -->
 <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 
 <!-- Introspector        -->
 <listener>
 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
 </listener>
 
 <filter>
 <filter-name>encoding</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>encoding</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <!--   DispatcherServlet -->
 <servlet>
 <servlet-name>maven_SSM</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <!--   springMVC      -->
 <!--          ,      classpath    [servlet-name]-servlet.xml    springmvc01-servlet.xml -->
 <init-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:springmvc.xml</param-value>
 </init-param>
 </servlet>
 
 <servlet-mapping> 
  <servlet-name>maven_SSM</servlet-name> 
  <url-pattern>/index</url-pattern> 
 </servlet-mapping>
 
 <!--    *.do, *.action(  ) / (  ):         spring mvc  ,                ,           
  /* :         -->
 <servlet-mapping>
 <servlet-name>maven_SSM</servlet-name>
 <url-pattern>/</url-pattern>
 </servlet-mapping> 
</web-app>
여기까지 기본 설정 이 모두 완료 되 었 습 니 다.jar 패키지 도 자동 으로 의존 합 니 다.후속 자바 코드 를 테스트 하고 작성 합 니 다.
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기