java常用基础配置文件

欢迎使用Markdown编辑器写博客

mybatis.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>
    <environments default="development">
        <environment id="development">
            <!-- 配置mysql事务处理 -->
            <transactionManager type="JDBC" />
            <!-- 配置数据库连接信息 并启用Mybatis的连接池-->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/usermanager" />
                <property name="username" value="root" />
                <property name="password" value="111111" />
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <!-- 配置选择以xml文件的方式使用mybatis -->
        <!-- <mapper resource="com/mapping/UserMapper.xml"/> -->
        <!-- 以注解的方式来使用MyBatis 把所有的接口都在这里声明 -->
        <mapper class="com.dao.UserMapper"/> 
    </mappers>
</configuration>

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

    <!-- 
    项目选用注解来标识bean对象,因此需要配置spring框架扫描注解的包路径
     -->
    <context:component-scan base-package="com.dao"></context:component-scan>
    <context:component-scan base-package="com.service"></context:component-scan>
    <context:component-scan base-package="com.web.controller"></context:component-scan>

    <!-- 
        告知spring数据库jdbc.properties的位置
     -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- 
           配置数据库连接用的连接池信息   选用dbcp连接池
     -->
    <bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="initialSize" value="${jdbc.initialSize}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"></property>
    </bean>

    <!-- 加上spring jdbctemplate的配置项 -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

</beans>

类加载过程代码

public class TestJDBCDemo {

    public void func(Object... array){
        for(Object data : array){
            System.out.print(data + " ");
        }
        System.out.println();
    }

    public void testJDBC(){
        //DriverManager   Connection   Statement(容易造成SQL注入式错误)  Preparement(带预编译的SQL)

    }

    public static int count(){
         return 1%9;
    }

    public static void main(String[]args) throws Exception{
         //System.out.println(count());

        try {
            Class<?> userclass = Class.forName("com.bean.User",true,new MyClassLoader());
            Object user = (userclass.newInstance());
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

class MyClassLoader extends ClassLoader{

    //根据类的包路径,在指定路径下去寻找class字节码文件
    @Override
    protected Class<?> findClass(String name1) throws ClassNotFoundException {
        // TODO Auto-generated method stub
        String root = "D:/";
        //D:/com/bean/User.class
        String path = root+name1.replace(".", "/")+".class";
        File file = new File(path);
        System.out.println("name:" + path);

        byte[] buff = null;

        try {
            FileInputStream in = new FileInputStream(file);
            buff = new byte[in.available()];
            int len = in.read(buff);
            in.close();

            //defineClass 就是从class字节码文件中生成类的Class对象
            Class<?> c = this.defineClass(name1, buff, 0, buff.length);
            return c;
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return super.findClass(path);
    }
}

Tomcat的server.xml设置

<Connector URIEncoding="UTF-8" acceptCount="600" connectionTimeout="20000" maxThreads="600" port="80" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>

<Connector SSLEnabled="true" clientAuth="false" keystoreFile="D:\tomcat.keystore" keystorePass="021602" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/>

log4j(根目录下)

## debug 级别

log4j.rootLogger=DEBUG,Console



log4j.appender.Console=org.apache.log4j.ConsoleAppender  

log4j.appender.Console.Target=System.out  

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

log4j.appender.Console.layout.ConversionPattern=%d{yyyy-MM-dd-HH\:mm\:ss,SSS} [%t]  [%c] [%p] - %m%n  



log4j.logger.com.mybatis=DEBUG  /


##输出sql 语句

log4j.logger.java.sql.Connection=DEBUG  

log4j.logger.java.sql.Statement=DEBUG  

log4j.logger.java.sql.PreparedStatement=DEBUG</strong>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值