尝试使用 Gradle 执行引导运行时出错 - Spring MVC
Error trying to do a bootRun with Gradle - Spring MVC
我正在尝试使用 Gradle - Spring MVC 使用 eclipse 进行引导运行,但出现此错误:
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'.
服务器和 JPA Hibernate 似乎加载后出现。
Console 中也出现了这个:
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
这是我的 build.gradle 文件:
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'
}
这是我的 Application.java class:
@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<IDialect> dialects = new HashSet<IDialect>();
dialects.add(new SpringSecurityDialect());
dialects.add(new LayoutDialect());
engine.setAdditionalDialects(dialects);
LinkedHashSet<ITemplateResolver> templateResolvers = new LinkedHashSet<ITemplateResolver>(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");
}
}
}
我在 运行 启动 Spring 引导应用程序时收到类似的错误消息。在应用程序文件夹内 i 运行 ./gradlew setMemDb bootRun.
我的解决方案是 运行,
- ./gradlew clean
- ./gradlew build
然后又是原来的命令,./gradlew setMemDb bootRun.
我猜这个问题的原因可能是导致这些错误的临时文件。
希望对您有所帮助
我遇到了类似的错误,但原因是其他原因。所以我认为它可能值得分享:
我的问题是我已经将 Tomcat 运行 作为一项单独的服务,所以我必须先终止它。
仅供参考,命令是:sudo service tomcat8 stop
然后我做了 ./gradlew clean
然后 ./gradlew bootRun
我必须在项目的根路径中执行
gradle clean
和
gradle build
注意:如果由于某种原因在构建命令中不起作用,请删除路径 node_modules 并重试
也把gradle版本更新到最新版本,可以帮到我们
每当我们 运行 启动 运行 的项目时,它会自动清理和重建说你可以使用命令 运行
./gradlew setMemDb bootRun
并希望它在 运行宁期间不会停止。
我曾经遇到过同样的问题,然后发现配置文件丢失了,
下面是 运行 带有配置文件的应用程序的命令,这里我们使用 dev 作为配置文件
SPRING_PROFILES_ACTIVE=dev ./gradlew bootRun
我正在尝试使用 Gradle - Spring MVC 使用 eclipse 进行引导运行,但出现此错误:
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'.
服务器和 JPA Hibernate 似乎加载后出现。
Console 中也出现了这个:
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
这是我的 build.gradle 文件:
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' }
这是我的 Application.java class:
@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<IDialect> dialects = new HashSet<IDialect>(); dialects.add(new SpringSecurityDialect()); dialects.add(new LayoutDialect()); engine.setAdditionalDialects(dialects); LinkedHashSet<ITemplateResolver> templateResolvers = new LinkedHashSet<ITemplateResolver>(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"); } } }
我在 运行 启动 Spring 引导应用程序时收到类似的错误消息。在应用程序文件夹内 i 运行 ./gradlew setMemDb bootRun.
我的解决方案是 运行,
- ./gradlew clean
- ./gradlew build
然后又是原来的命令,./gradlew setMemDb bootRun.
我猜这个问题的原因可能是导致这些错误的临时文件。
希望对您有所帮助
我遇到了类似的错误,但原因是其他原因。所以我认为它可能值得分享:
我的问题是我已经将 Tomcat 运行 作为一项单独的服务,所以我必须先终止它。
仅供参考,命令是:sudo service tomcat8 stop
然后我做了 ./gradlew clean
然后 ./gradlew bootRun
我必须在项目的根路径中执行
gradle clean
和
gradle build
注意:如果由于某种原因在构建命令中不起作用,请删除路径 node_modules 并重试
也把gradle版本更新到最新版本,可以帮到我们
每当我们 运行 启动 运行 的项目时,它会自动清理和重建说你可以使用命令 运行
./gradlew setMemDb bootRun
并希望它在 运行宁期间不会停止。
我曾经遇到过同样的问题,然后发现配置文件丢失了,
下面是 运行 带有配置文件的应用程序的命令,这里我们使用 dev 作为配置文件
SPRING_PROFILES_ACTIVE=dev ./gradlew bootRun