您的位置:首页 > 数据库 > Oracle

ssm框架+oracle数据库配置

2018-01-11 15:55 274 查看

jdbc.properties  配置

driver=oracle.jdbc.driver.OracleDriver

url=jdbc:oracle:thin:@localhost:1521:orcl

username=scott

password=123456

initialSize=10

maxActive=100

maxIdle=20

minIdle=1

maxWait=60000


spring-mvc.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:mvc="http://www.springframework.org/schema/mvc" 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.2.xsd  

                        http://www.springframework.org/schema/context  

                        http://www.springframework.org/schema/context/spring-context-3.2.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
    

    <!-- 扫描 -->

    <context:component-scan base-package="com"></context:component-scan>

    

    <!-- mvc注解驱动 -->

<mvc:annotation-driven></mvc:annotation-driven>

    <!-- 视图解析器 -->

    <bean

        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="viewClass"

            value="org.springframework.web.servlet.view.JstlView"></property>

        <property name="prefix" value="/"></property>

        <property name="suffix" value=".jsp"></property>

    </bean>

    <!-- 静态资源访问 -->

    <mvc:resources location="/js/" mapping="/js/**"/>

    <mvc:resources location="/css/" mapping="/css/**"/>

</beans>


spring-mybatis.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:mvc="http://www.springframework.org/schema/mvc" 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.2.xsd  

                        http://www.springframework.org/schema/context  

                        http://www.springframework.org/schema/context/spring-context-3.2.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
    

    <context:component-scan base-package="com.dao,com.service"></context:component-scan>

    

    <!-- 加载jdbc属性文件 -->

 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

        <property name="location" value="classpath:config/jdbc.properties"></property>

    </bean>

    

    <!-- 配置数据源 -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

        <property name="driverClassName" value="${driver}" />

        <property name="url" value="${url}" />

        <property name="username" value="${username}" />

        <property name="password" value="${password}" />

        <!-- 初始化连接大小 -->

        <property name="initialSize" value="${initialSize}"></property>

        <!-- 连接池最大数量 -->

        <property name="maxActive" value="${maxActive}"></property>

        <!-- 连接池最大空闲 -->

        <property name="maxIdle" value="${maxIdle}"></property>

        <!-- 连接池最小空闲 -->

        <property name="minIdle" value="${minIdle}"></property>

        <!-- 获取连接最大等待时间 -->

        <property name="maxWait" value="${maxWait}"></property>

    </bean>

    

    <!-- 配置sqlSessionFactory -->

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

        <property name="dataSource" ref="dataSource"></property>

        <!-- 加载mybatis全局配置文件 -->

        <property name="configLocation" value="classpath:config/sqlMapConfig.xml"></property>

        <!-- 加载mybatis映射文件 -->

        <property name="mapperLocations" value="classpath:com/dao/*.xml"></property>

    </bean>

    

    

    <!-- 配置dao接口扫描bean -->

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

        <!-- 基包 -->

        <property name="basePackage" value="com.dao"></property>

        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

    </bean>

    

    <!-- 声明式事务 -->

    <!-- 事务管理器 -->

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource"></property>

    </bean>

    <!-- 注解 -->

    <tx:annotation-driven transaction-manager="transactionManager"/>

    

    

</beans>


log4j.properties 配置

log4j.rootLogger=debug,stdout,logfile

### 把日志信息输出到控制台 ###

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

#log4j.appender.stdout.Target=System.err

log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout

### 把日志信息输出到文件:jbit.log ###

log4j.appender.logfile=org.apache.log4j.FileAppender

log4j.appender.logfile.File=D:/test.log

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss} %F %p %m%n

 

###显示SQL语句部分

log4j.logger.com.ibatis=DEBUG

log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG

log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG

log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG

log4j.logger.Java.sql.Connection=DEBUG

log4j.logger.java.sql.Statement=DEBUG

log4j.logger.java.sql.PreparedStatement=DEBUG


web.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://
90da
java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>classpath:config/spring-mybatis.xml</param-value>

 </context-param>

 <filter>

  <filter-name>encoder</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>encoder</filter-name>

  <url-pattern>/*</url-pattern>

 </filter-mapping>

 <listener>

  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

 </listener>

 <servlet>

  <servlet-name>dispatcherServlet</servlet-name>

  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  <init-param>

   <param-name>ContextConfigLocation</param-name>

   <param-value>classpath:config/spring-mvc.xml</param-value>

  </init-param>

  <load-on-startup>1</load-on-startup>

 </servlet>

 <servlet-mapping>

  <servlet-name>dispatcherServlet</servlet-name>

  <url-pattern>/</url-pattern>

 </servlet-mapping>

 <!-- 配置SpringMVC Servlet -->

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: