标签:new required 连接 ica 个人 one lan ref add
Spring applicationconfig.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:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"><!-- 配置数据源 ,连接池用的阿里druid--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"/><!--<property name="url" value="jdbc:mysql://IP+数据库"/><property name="username" value="用户名"/><property name="password" value="密码"/>--><property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/><property name="username" value="root"/><property name="password" value="root"/></bean><!-- 配置mybatis的sqlSessionFactory --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><!-- 自动扫描mappers.xml文件 --><property name="mapperLocations" value="classpath:mapper/*.xml"></property><!-- mybatis配置文件 --><property name="configLocation" value="classpath:mybatis-config.xml"></property></bean><!-- DAO --><bean id="infoDao" class="org.mybatis.spring.mapper.MapperFactoryBean"><property name="mapperInterface" value="net.xjdsz.dao.InfoDao" /><property name="sqlSessionFactory" value="sqlSessionFactory"></property></bean></beans>
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" ><mapper namespace="net.xjdsz.dao.InfoDao"><!-- 查询条件:账号密码用户类型. 0第一个参数,1第二个参数,对应dao接口参数 --><select id="FindAllInfos" resultType="net.xjdsz.model.Info">SELECT * FROM info limit 1</select><!--<select id="getAllUsers" resultMap="userResult">SELECT USER_CODE,USER_NAME,USER_PWD,CREATE_DATEFROM BLOG_USER</select>--></mapper>
<?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><mappers><mapper resource="mapper/info.xml"/></mappers></configuration>


package net.xjdsz.service.impl;import net.xjdsz.dao.InfoDao;import net.xjdsz.model.Info;import net.xjdsz.service.InfoService;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/*** Created by dingshuo on 2017/1/3.*/public class InfoServiceImpl implements InfoService {private InfoDao infoDao;@Overridepublic Info DoWork() {Info info=infoDao.FindAllInfos();return info;}public static void main(String[] args){ApplicationContext ctx = null;ctx = new ClassPathXmlApplicationContext("spring-config/ApplicationContext.xml");InfoDao infoDao=(InfoDao)ctx.getBean("infoDao");Info aaa=infoDao.FindAllInfos();System.out.println(aaa.toString());}}
Connected to the target VM, address: ‘127.0.0.1:58958‘, transport: ‘socket‘一月 03, 2017 5:31:51 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@7a0ac6e3: startup date [Tue Jan 03 17:31:51 CST 2017]; root of context hierarchy一月 03, 2017 5:31:51 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions信息: Loading XML bean definitions from class path resource [spring-config/ApplicationContext.xml]一月 03, 2017 5:31:52 下午 com.alibaba.druid.pool.DruidDataSource info信息: {dataSource-1} initedDisconnected from the target VM, address: ‘127.0.0.1:58958‘, transport: ‘socket‘ID:1,TM:Thu Nov 10 00:00:00 CST 2016,DESC:nihao ,FLAG:0Process finished with exit code 0
标签:new required 连接 ica 个人 one lan ref add
原文地址:http://www.cnblogs.com/tilv37/p/6247270.html