자바 상용 기본 프로필

17188 단어 자바
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

좋은 웹페이지 즐겨찾기