錯誤:
[main] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@50e433c3]
或者
Access denied for user 'Administrator'@'localhost' (using password: YES)
可能的問題有兩個,第一個是加載的時候還沒有加載數據庫配置,就先初始化sqlSessionFactory,使用sqlSessionFactoryBeanName,傳入的只是名字,非bean,所以不會引發提前初始化問題。
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入SqlSessionFactory-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 給出需要掃描的Dao接口-->
<property name="basePackage" value="org.main.dao"/>
</bean>
第二個是username這個屬性被系統的username覆蓋,所以它會報錯,建議改爲其他變量名,比如user
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://127.0.0.1:3306/seckill?useUnicode=true&characterEncoding=utf8
username=root
password=root