title: Error trying to do a bootRun with Gradle - Spring MVC
body: <p>I am trying to do a bootRun with Gradle - Spring MVC using eclipse but this error appears:</p>
  
  <blockquote>
  <pre><code>Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
  Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.1-bin.zip'.
  </code></pre>
  </blockquote>
  
  <p>That appears after the Server and JPA Hibernate seems to be load.</p>
  
  <p>In the Console also appears this:</p>
  
  <blockquote>
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: Tomcat connector in failed state
  at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:154)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:272)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:132)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
  at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
  at palmaslab.mapas.config.Application.main(Application.java:71)
  :bootRun FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
  Execution failed for task ':bootRun'.
  Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 9.299 secs
  [sts] Build failed
  </code></pre>
  </blockquote>
  
  <p>This is my build.gradle file:</p>
  
  <blockquote>
  <pre><code>  buildscript {
      ext {
          springBootVersion = '1.1.9.RELEASE'
      }
      repositories {
          maven { url "http://repo.spring.io/libs-snapshot" }
          mavenLocal()
      }
      dependencies {
          classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE")
      }
  }
  apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'idea'
  apply plugin: 'spring-boot'
  apply plugin: 'war'
  apply plugin: 'jetty'
  apply plugin: 'application'
  sourceCompatibility = 1.7
  targetCompatibility = 1.7
  war {
     version =  '0.1.0'
  }
  repositories {
      mavenCentral()
      maven { url "http://repo.spring.io/libs-snapshot" }
      maven { url "http://maven.springframework.org/milestone" }
      flatDir {
          dirs 'lib'
      }
  }
  dependencies {
  compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
  compile("org.springframework.boot:spring-boot-starter-tomcat:${springBootVersion}")
  compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
  compile("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}")
      compile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
  compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
      compile("org.springframework.data:spring-data-rest-webmvc")
   compile("org.springframework.boot:spring-boot-starter-security:1.0.2.RELEASE")
      compile("org.springframework.security.oauth:spring-security-oauth2:2.0.0.RC2")
      compile("org.springframework.security.oauth:spring-security-oauth2-javaconfig:1.0.0.M1")
  compile("org.hsqldb:hsqldb")
  compile("com.h2database:h2")
  compile("com.google.guava:guava:17.0")
      compile("org.apache.commons:commons-lang3:3.3.2")
      compile("org.apache.httpcomponents:httpclient:4.3.4")
      compile("com.squareup.retrofit:retrofit:1.6.0")
      compile("commons-io:commons-io:2.4")
  compile("com.github.davidmarquis:fluent-interface-proxy:1.3.0")
      compile ("org.springframework.boot:spring-boot-starter-security:1.0.2.RELEASE")
     compile ("javax.servlet:jstl:1.2")
     compile ("commons-fileupload:commons-fileupload:1.3.1")
      testCompile("junit:junit")
      compile("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect") 
      compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3")
       compile("org.thymeleaf:thymeleaf-spring4")
  def poiVersion = "3.10.1"
      compile "org.apache.poi:poi:${poiVersion}"
      compile "org.apache.poi:poi-ooxml:${poiVersion}"
   compile "org.apache.poi:ooxml-schemas:1.1"
  }
  jar {
      baseName = 'gs-uploading-files'
      version =  '0.1.0'
  }
  task wrapper(type: Wrapper) {
      gradleVersion = '1.11'
  }
  </code></pre>
  </blockquote>
  
  <p>And this is my Application.java class:</p>
  
  <blockquote>
  <pre><code>  @EntityScan(basePackages= "palmaslab.mapas.repository")
  @EnableJpaRepositories(basePackages= "palmaslab.mapas.repository"/*.PostoSaudeRepository.class*/)
  @Configuration
  @EnableAutoConfiguration
  @ComponentScan(basePackages="palmaslab.mapas.controller")
  @Import({palmaslab.mapas.security.SecurityConfiguration.class})
  @EnableWebMvc
  @PropertySource("application.properties")
  public class Application extends WebMvcConfigurerAdapter{
  private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
          "classpath:/META-INF/resources/", "classpath:/resources/",
          "classpath:/static/", "classpath:/public/" };
  public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
           }
       @Bean
          public LocalContainerEntityManagerFactoryBean entityManagerFactory(
                  DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
              LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
              lef.setDataSource(dataSource);
              lef.setJpaVendorAdapter(jpaVendorAdapter);
              lef.setPackagesToScan("palmaslab.mapas.controller");
              return lef;
          }
  @Bean
          public JpaVendorAdapter jpaVendorAdapter() {
              HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
              hibernateJpaVendorAdapter.setShowSql(true);
              hibernateJpaVendorAdapter.setGenerateDdl(true); //Auto creating scheme when true
              hibernateJpaVendorAdapter.setDatabase(Database.H2);//Database type
              return hibernateJpaVendorAdapter;
          }
  @Bean  
  public SpringTemplateEngine templateEngine() { 
              SpringTemplateEngine engine = new SpringTemplateEngine();
              Set&lt;IDialect&gt; dialects = new HashSet&lt;IDialect&gt;();
              dialects.add(new SpringSecurityDialect());
              dialects.add(new LayoutDialect());
              engine.setAdditionalDialects(dialects);
              LinkedHashSet&lt;ITemplateResolver&gt; templateResolvers = new LinkedHashSet&lt;ITemplateResolver&gt;(2);
              templateResolvers.add(templateResolverServlet());
              templateResolvers.add(layoutTemplateResolverServlet());
              engine.setTemplateResolvers(templateResolvers);
              return engine;
          }
  @Bean 
  public ServletContextTemplateResolver layoutTemplateResolverServlet() { 
              ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
              templateResolver.setPrefix("/WEB-INF/layout/");
              templateResolver.setSuffix("");
              templateResolver.setTemplateMode("LEGACYHTML5");
              templateResolver.setOrder(1);
              templateResolver.setCacheable(false);
              return templateResolver;
          }
  @Bean 
          public ServletContextTemplateResolver templateResolverServlet() { 
              ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
              templateResolver.setPrefix("/WEB-INF/view/");
              templateResolver.setSuffix(".html");
              templateResolver.setTemplateMode("LEGACYHTML5");
          //    templateResolver.setTemplateMode("HTML5");
              templateResolver.setOrder(2);
              templateResolver.setCacheable(false);
              return templateResolver;
          }
  @Bean 
          public ViewResolver thymeleafViewResolver() { 
              ThymeleafViewResolver resolver = new ThymeleafViewResolver();
              resolver.setTemplateEngine(templateEngine());
              resolver.setOrder(1);
              resolver.setCharacterEncoding("ISO-8859-1");
              resolver.setCache(false);
              return resolver;
          }
  @Bean
      public ServletRegistrationBean dispatcherRegistration() {
          ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet());
          registration.addUrlMappings("/");
          registration.setLoadOnStartup(1);
          return registration;
  }
  @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  @Bean
      public DispatcherServlet dispatcherServlet() {
          return new DispatcherServlet();
      }
      @Bean
      public MultipartConfigElement multipartConfigElement() {
          MultipartConfigFactory factory = new MultipartConfigFactory();
          factory.setMaxFileSize("999999KB");
          factory.setMaxRequestSize("999999KB");
          return factory.createMultipartConfig();
      }
       @Bean
        public MultipartResolver multipartResolver() {
          CommonsMultipartResolver resolver = new CommonsMultipartResolver();
          resolver.setMaxUploadSize(1000000000);
          return resolver;
        }
  @Bean
      public CommonsMultipartResolver filterMultipartResolver() {
          CommonsMultipartResolver resolver=new CommonsMultipartResolver();
          resolver.setDefaultEncoding("ISO-8859-1");
          resolver.setMaxUploadSize(500000000);
          resolver.setMaxInMemorySize(500000000);
          return resolver;
      }
    @Bean
      public EmbeddedServletContainerFactory servletContainer() {
          TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
          factory.setPort(8080);
          factory.setSessionTimeout(5, TimeUnit.MINUTES);
          //factory.addErrorPages(new ErrorPage(HttpStatus.404, "/notfound.html"));
          return factory;
      }
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          if (!registry.hasMappingForPattern("/webjars/**")) {
              registry.addResourceHandler("/webjars/**").addResourceLocations(
                      "classpath:/META-INF/resources/webjars/");
          }
          if (!registry.hasMappingForPattern("/locals/**")) {
              registry.addResourceHandler("/locals/**").addResourceLocations(
                       "classpath:/locals");
  }
      }
  }
  </code></pre>
  </blockquote>