欢迎使用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">
<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
<?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">
<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(){
}
public static int count(){
return 1%9;
}
public static void main(String[]args) throws Exception{
try {
Class<?> userclass = Class.forName("com.bean.User",true,new MyClassLoader());
Object user = (userclass.newInstance());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
class MyClassLoader extends ClassLoader{
@Override
protected Class<?> findClass(String name1) throws ClassNotFoundException {
String root = "D:/";
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();
Class<?> c = this.defineClass(name1, buff, 0, buff.length);
return c;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
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>