title: Spring+ MyBatis+ mvn Project , java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:WEB-INF/myBatis-config.xml]
body: <p>I am using Spring 4.0.5 and MyBatis 3.2.7 with maven. I have my myBatis-config.xml file under WEB-INF/myBatis folder. While trying to create the sqlSessionFactory bean, I get the FileNotFoundError.</p>
  
  <p>This is my bean:</p>
  
  <pre><code>&lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
              &lt;property name="dataSource" ref="dataSource" /&gt;         
              &lt;property name="configLocation" value="myBatis/myBatis-config.xml" /&gt;
              &lt;property name="mapperLocations" value="classpath*:com/attinad/mappers/*.xml" /&gt;
              &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Stack Trace:</strong></p>
  
  <pre><code>SEVERE: Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/ds-config.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/myBatis/myBatis-config.xml]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:684)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
      at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/myBatis/myBatis-config.xml]
      at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
      at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:358)
      at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:340)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
      ... 21 more
  </code></pre>
  
  <p>I have tried putting /classpath*:WEB-INF/myBatis/myBatis-config.xml as the value. But it didn't help.</p>
  
  <p>Please help me find the solution as I have spent hours debugging this.</p>
  
  <p>Please find myBatis-config.xml file.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt;
   &lt;configuration&gt;
   &lt;settings&gt;
   &lt;setting name="cacheEnabled" value="true" /&gt;
   &lt;setting name="lazyLoadingEnabled" value="true" /&gt;
   &lt;setting name="multipleResultSetsEnabled" value="true" /&gt;
   &lt;setting name="useColumnLabel" value="true" /&gt;
   &lt;setting name="useGeneratedKeys" value="false" /&gt;
   &lt;setting name="defaultExecutorType" value="SIMPLE" /&gt;
   &lt;setting name="defaultStatementTimeout" value="100" /&gt;
   &lt;setting name="safeRowBoundsEnabled" value="false" /&gt;
   &lt;setting name="mapUnderscoreToCamelCase" value="false" /&gt;
   &lt;setting name="localCacheScope" value="SESSION" /&gt;
   &lt;setting name="jdbcTypeForNull" value="OTHER" /&gt;
   &lt;setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString" /&gt;
   &lt;/settings&gt; 
   &lt;typeAliases&gt;&lt;typeAlias type="classpath*:com.attinad.model.Employee" alias="Emp"/&gt;&lt;/typeAliases&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>My Mapper file EmployeeMapper.xml file is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;
  
  
  &lt;mapper namespace="com.attinad.dao.EmployeeMapperInterface"&gt;
  
  &lt;select id="getEmployeeWithId" parameterType="Long" resultType="Emp"&gt;
          select *  from
          employees where
          id=#{empId}
  
      &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>