title: Springboot : How to skip datasource configuration running tests
body: <p>I have a simple Springboot application which runs perfectly.
  My issue is that I made some tests which are running well on my computer but not on Jenkins.</p>
  
  <p>The reason is that I have 2 datasources protected by a firewall. A little "mvn clean install" on my computer works because its IP is trusted whereas Jenkins' one is not and cannot be. </p>
  
  <p>My tests don't need the datasources (everything is mocked) but when the application context is loaded, it fails because of a database connection timeout (->firewall)</p>
  
  <p>How can I skip the database part when tests are executed ? I tried with Profiles without success...</p>
  
  <p>Thanks in advance for your responses ;-)</p>
  
  <p>Here are main classes of my application</p>
  
  <p><strong>MyApp.java</strong></p>
  
  <pre><code>@SpringBootApplication
  @ComponentScan
  @EnableAutoConfiguration(exclude={JpaRepositoriesAutoConfiguration.class,
    DataSourceAutoConfiguration.class})
  @PropertySources({
    @PropertySource(MyApp.CLASSPATH_APPLICATION_PROPERTIES)
  })
  public class MyApp extends SpringBootServletInitializer {
    public static final String CLASSPATH_APPLICATION_PROPERTIES = "classpath:/application-${spring.profiles.active}.properties";
    ....
  }
  </code></pre>
  
  <p><strong>FirstDataSourceConfig.java</strong> (there is a second class for the other datasource)</p>
  
  <pre><code>@Configuration
  @Profile("prod")
  @EnableTransactionManagement
  @EnableJpaRepositories(
              entityManagerFactoryRef = "dbFirstEntityManager",
              transactionManagerRef = "dbFirstTransactionManager",
              basePackages = {"my.package.for.dao"})
  public class FirstDataSourceConfig {
      // Definition of LocalContainerEntityManagerFactoryBean, DataSource and Transaction manager
  }
  </code></pre>
  
  <p><strong>AbstractTest.java</strong></p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringApplicationConfiguration(classes = {MyApp.class})
  @ActiveProfiles("dev")
  public class AbstractTest {
  
      protected Logger LOGGER = Logger.getLogger(this.getClass());
  }
  </code></pre>
  
  <p><strong>AbstractControllerTest.java</strong></p>
  
  <pre><code>@WebAppConfiguration
  public class AbstractControllerTest extends AbstractTest {
  
      protected MockMvc mvc;
  
      @Autowired
      protected WebApplicationContext webApplicationContext;
  
      protected void setUp() {
          mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
      }
      ....
  }
  </code></pre>