No bean named 'sqlSessionFactory' is defined

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了No bean named 'sqlSessionFactory' is defined相关的知识,希望对你有一定的参考价值。

  其实程序给出这个错误已经很明确了,说你的sqlSessionFactory是未定义的。

  首先你要查看一下自己的web.xml文件是否配置了application*.xml

<!--设置spring 配置文件的位置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/spring/applicationContext-*.xml</param-value>
</context-param>
<!--springmvc前端控制器配置-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/spring/springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

然后查看你的application*.xml文件里面是否扫描了mapper接口,有没有注入sqlsessionFaction ,代码如下。
<!--sqlsessionFactory bean-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:config/mybatis/SqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>

<!--自动扫描mapper接口,并注入sqlsession-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.syw.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>

配置好后SqlMapConfig.xml中找相应文件就可以了。文件内容如下。

技术分享





































以上是关于No bean named 'sqlSessionFactory' is defined的主要内容,如果未能解决你的问题,请参考以下文章

No bean named 'transactionManager' is defined

No bean named 'springSecurityFilterChain' is defined

关于启动tomcat 找不到 No bean named '*****' is defined

服务器启动时 No bean named 'sessionFactory' is defined

No bean named 'B' is defined

ssh2整合: No bean named 'sessionFactory' is defined(求大神指点)