title: SpringBootTest for DAO JUnit test
body: <p>I am attempting the following unit test of a DAO.</p>
  
  <p>I am unable to get the DataSource recognized.</p>
  
  <p>Can I get a tip on how to resolve this?</p>
  
  <p>Details below</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringBootTest
  public class EntityDaoTest {
  
      @Autowired 
      protected EntityDao entityDao;
  
      @Before
      public void setup()
      {
  
      }
  
      @Test
      public void test() throws InternalServerException
      {
          List&lt;Entity&gt; entities = entityDao.list();
          assert(entities.size()==0);
      }
  }
  </code></pre>
  
  <p>The relevant aspects of the DAO class are as follows</p>
  
  <pre><code>@Repository
  public class EntityDao extends GenericDao&lt;Entity&gt;{
  
      public EntityDao(DataSource dataSource) {/.../}
  }
  </code></pre>
  
  <p>My src/test/resources/application.properties file is as follows</p>
  
  <pre><code># Database
  spring.datasource.url=jdbc:mysql://localhost:3306/db
  spring.datasource.username=dbuser
  spring.datasource.password=dbpass
  </code></pre>
  
  <p>Trace from running as JUnit test in Eclipse</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to load ApplicationContext
  ...
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityController': Unsatisfied dependency expressed through field 'entityDao': Error creating bean with name 'entityDao' defined in file .../target/classes/hitstpa/dao/EntityDao.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type [javax.sql.DataSource] found for dependency [javax.sql.DataSource]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; 
  
  ...
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityDao' defined in file [/home/fmason/workspace/hitstpa/target/classes/hitstpa/dao/EntityDao.class]: Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type [javax.sql.DataSource] found for dependency [javax.sql.DataSource]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] found for dependency [javax.sql.DataSource]: expected at least 1 bean which qualifies as autowire candidate for this dependency. ...`
  </code></pre>
  
  <p>Application structure</p>
  
  <p>-src</p>
  
  <p>--main</p>
  
  <p>---java</p>
  
  <p>----Application.java</p>
  
  <p>----com</p>
  
  <p>----hitstpa</p>
  
  <p>-----controller</p>
  
  <p>-----dao</p>
  
  <p>------EntityDao.java</p>
  
  <p>-----model</p>
  
  <p>---resources</p>
  
  <p>----application.properties</p>
  
  <p>--test</p>
  
  <p>---java</p>
  
  <p>----hitstpa</p>
  
  <p>-----dao</p>
  
  <p>------EntityDaoTestDOTjava</p>
  
  <p>---resources</p>
  
  <p>----applicationDOTproperties</p>