发表于: 2016-11-04 20:39:45
2 2295
终于登上来了!!
dataSource ${jdbc_driverClassName}占位符的问题终于解决。两个星期了,任务一花的时间很长,一是奔波于校招,二是对这个问题的无奈,大概弄了3.4天。一时间思路混乱然后也是搞搞停停。对于这种问题第一想法是先百度,然后谷歌。网上的答案呢又是差不多的,弄来弄去也只是弄个大概明白道理,到具体源码,bean的生命周期,这些并没有去深入了解,这大概是我找个问题找这么久的原因吧!
然后说说问题是怎么解决的,其实我也不知道是怎么解决的。昨天面试回来,想想这个问题不能一直放在那里。百度我是不想了。然后把以前的做过的项目的配置对比改了一下,然后,然后就可以了。把正确配置贴下来,留个纪念吧!
spring-mabatis.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
<!-- 采用注释的方式配置bean -->
<context:annotation-config />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc_driverClassName}"></property>
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" />
<!-- 连接池最大使用连接数 -->
<property name="maxActive">
<value>20</value>
</property>
<!-- 初始化连接大小 -->
<property name="initialSize">
<value>1</value>
</property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait">
<value>60000</value>
</property>
<!-- 连接池最大空闲 -->
<property name="maxIdle">
<value>20</value>
</property>
<!-- 连接池最小空闲 -->
<property name="minIdle">
<value>3</value>
</property>
<!-- 自动清除无用连接 -->
<property name="removeAbandoned">
<value>true</value>
</property>
<!-- 清除无用连接的等待时间 -->
<property name="removeAbandonedTimeout">
<value>180</value>
</property>
<!-- 连接属性 -->
<property name="connectionProperties">
<value>clientEncoding=UTF-8</value>
</property>
</bean>
<bean id="plsqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
<property name="mapperLocations">
<value>classpath:mapper/*.xml</value>
</property>
</bean>
<!-- spring与mybatis整合配置,扫描所有dao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.wowson.dao"></property>
<property name="sqlSessionFactoryBeanName" value="plsqlSessionFactory" />
</bean>
<!-- 对数据源进行事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- p:dataSource-ref="dataSource" > -->
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
spring.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- classpath:是指的当前类文件的目录下。 -->
<!-- 引入jdbc配置文件 -->
<!-- <bean id="propertyConfigurerForAnalysis"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:config.properties</value>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean> -->
<context:property-placeholder location="classpath:config.properties" ignore-unresolvable="true"/>
<!-- 与上面的配置等价,下面的更容易理解 -->
<!-- 扫描文件(自动将servicec层注入) -->
<!-- (自动注入) -->
<context:component-scan base-package="com.wowson.service" />
</beans>
明天任务:maven web工程在任务一已经是了。那明天的话就了解Rest接口格式。编写,并通过task1中的service实现
评论