maven项目中mysql改oracle_Maven+oracle+SSM搭建简单项目的方法

简单谈一下maven搭建 ssm 项目 (使用数据库oracle,比 mysql 麻烦一点,所以这里谈一下)

在创建maven 的web项目时,常常会缺了main/java , main/test 两个文件夹。

解决方法:

① : 在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace default jre就可以了。 (推荐使用这种)

② :手动创建 目录。切换视图采用Navigator视图,直接在src/main目录下建立 Java目录。

项目目录结构:

adfc03731d43d1fea8c2b2d4bc9ccc92.png

重要的配置文件:

对象模型配置文件: pom.xml

Spring的配置文件:applicationContext.xml

spring MVC配置文件: springmvc.xml

数据库配置文件: jdbc.properties

日志配置文件: log4j.properties

mybatis配置文件: mybatis-config.xml

网络程序配置文件:web.xml

首先配置pom.xml

pom.xml 主要描述了项目的maven坐标,依赖关系,自动引入jar包

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

com.krry

maven_SSM

0.0.1-SNAPSHOT

maven_SSM

http://maven.apache.org

junit

junit

4.11

test

javax.servlet

servlet-api

3.0-alpha-1

provided

jstl

jstl

1.2

provided

javax.servlet.jsp

jsp-api

2.2

provided

log4j

log4j

1.2.17

org.springframework

spring-context

4.2.1.RELEASE

org.springframework

spring-jdbc

4.2.1.RELEASE

org.springframework

spring-webmvc

4.2.1.RELEASE

com.fasterxml.jackson.core

jackson-core

2.5.4

com.fasterxml.jackson.core

jackson-annotations

2.5.4

com.fasterxml.jackson.core

jackson-databind

2.5.4

org.hibernate

hibernate-validator

5.1.1.Final

commons-io

commons-io

2.4

commons-fileupload

commons-fileupload

1.3.1

org.apache.commons

commons-lang3

3.3.2

commons-codec

commons-codec

1.9

com.oracle

ojdbc6

12.1.0.2.0

com.cloudhopper.proxool

proxool

0.9.1

com.cloudhopper.proxool

proxool-cglib

0.9.1

org.mybatis

mybatis

3.3.1

org.mybatis

mybatis-spring

1.2.4

com.github.pagehelper

pagehelper

4.2.1

maven-compiler-plugin

1.7

1.7

maven-war-plugin

2.4

3.0

maven_SSM

这里说一下maven工程利用pom.xml导入oracle驱动包的问题:

由于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的命令行界面,进入驱动包ojdbc6的目录,然后运行:

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=12.1.0.2.0 -Dpackaging=jar -Dfile=ojdbc6.jar

显示"BUILD SUCCESS" 成功,就会自动导入你的maven本地仓库。

然后就可以在maven项目里添加dependency,各坐标对应上面这个命令的个元素,如下:

com.oracle

ojdbc6

12.1.0.2.0

Spring的配置文件:applicationContext.xml

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

">

p:location="classpath:jdbc.properties" p:fileEncoding="utf-8" />

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

spring MVC配置文件:springmvc.xml

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

">

text/plain;charset=UTF-8

text/html;charset=UTF-8

NON_NULL

application/json;charset=UTF-8

application/x-www-form-urlencoded;charset=UTF-8

class="org.springframework.web.multipart.commons.CommonsMultipartResolver"

p:defaultEncoding="utf-8">

209715200

4096

数据库配置文件: 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

/p>

PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

网络程序配置文件:web.xml

maven_SSM

index

contextConfigLocation

classpath:applicationContext.xml

org.springframework.web.context.ContextLoaderListener

org.springframework.web.util.IntrospectorCleanupListener

encoding

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

encoding

/*

maven_SSM

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml

maven_SSM

/index

maven_SSM

/

到这里,基本配置全部完成,jar包也自动依赖。就进行测试和编写后续 java 的代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值