java常用基础配置文件

欢迎使用Markdown编辑器写博客

mybatis.xml



<configuration>
    <environments default="development">
        <environment id="development">
            
            <transactionManager type="JDBC" />
            
            <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>
        
        
        
        <mapper class="com.dao.UserMapper"/> 
    mappers>
configuration>

spring.xml


<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">

    
    <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>

    
    <context:property-placeholder location="classpath:jdbc.properties"/>

    
    <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>

    
    <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

你可能感兴趣的:(java)