当我尝试在 HEROKU 中打开已部署的应用程序时出现此问题。 Spring Framework类ResponseErrorHandler正在抛出NoClassDefFoundError。我尝试更改xml和属性文件,但是徒劳无功。
[33m2014-12-15T12:12:46.641119 + 00:00 heroku [web.1]:←[0m使用命令
java -Dserver.port=39847 -Ddatabase.url=postgres://genreimfcnjetj:Swt7eGbTANi2-X7tBru0wTX4GT@ec2-54-235-76-206.compute-1.amazonaws.com:5432/d9108hum0pg29o -Xss512k -XX:+UseCompressedOops -Dspring.profiles.active=production -jar target/*.jar
启动流程 [33m2014-12-15T12:12:47.517755 + 00:00 app [web.1]:←[0m at java.lang.Class.getDeclaredMethods0(Native Method) [33m2014-12-15T12:12:47.518480 + 00:00 app [web.1]:←[0m at java.lang.Class.privateGetMethodRecursive(Class.java:3035) [33m2014-12-15T12:12:47.517563 + 00:00 app [web.1]:←[0m线程中的异常" main" java.lang.NoClassDefFoundError:org / springframework / web / client / ResponseErrorHandler [33m2014-12-15T12:12:47.518545 + 00:00 app [web.1]:←[0m at java.lang.Class.getMethod0(Class.java:3005) [33m2014-12-15T12:12:47.519084 + 00:00 app [web.1]:←[0m at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) [33m2014-12-15T12:12:47.319339 + 00:00 app [web.1]:←[0m拿起JAVA_TOOL_OPTIONS:-Xmx384m -Djava.rmi.server.useCodebaseOnly = true [33m2014-12-15T12:12:47.519022 + 00:00 app [web.1]:←[0m at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) [33m2014-12-15T12:12:47.518428 + 00:00 app [web.1]:←[0m at java.lang.Class.privateGetDeclaredMethods(Class.java:2688) [33m2014-12-15T12:12:47.518938 + 00:00 app [web.1]:←[0m at java.lang.Class.getMethod(Class.java:1771) [33m2014-12-15T12:12:47.519224 + 00:00 app [web.1]:←[0m引起:java.lang.ClassNotFoundException:org.springframework.web.client.ResponseErrorHandler [33m2014-12-15T12:12:47.520145 + 00:00 app [web.1]:←[0m at java.net.URLClassLoader.findClass(URLClassLoader.java:360) [33m2014-12-15T12:12:47.519277 + 00:00 app [web.1]:←[0m at java.net.URLClassLoader $ 1.run(URLClassLoader.java:372) [33m2014-12-15T12:12:47.519388 + 00:00 app [web.1]:←[0m at java.security.AccessController.doPrivileged(Native Method) [33m2014-12-15T12:12:47.520395 + 00:00 app [web.1]:←[0m at java.lang.ClassLoader.loadClass(ClassLoader.java:357) [33m2014-12-15T12:12:47.520237 + 00:00 app [web.1]:←[0m at java.lang.ClassLoader.loadClass(ClassLoader.java:424) [33m2014-12-15T12:12:47.519339 + 00:00 app [web.1]:←[0m at java.net.URLClassLoader $ 1.run(URLClassLoader.java:361) [33m2014-12-15T12:12:47.520312 + 00:00 app [web.1]:←[0m at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308) [33m2014-12-15T12:12:47.520441 + 00:00 app [web.1]:←[0m ... 7更多 [33m2014-12-15T12:12:48.201159 + 00:00 heroku [web.1]:←[0m进程退出状态1 [33m2014-12-15T12:12:48.209235 + 00:00 heroku [web.1]:←[0m状态从开始变为崩溃
请给我一些帮助。
分享与ResponseErrorHandler相关的类。
CustomerErrorResponseHandler.java
package rentitnew;
import java.io.IOException;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.ResponseErrorHandler;
class CustomResponseErrorHandler implements ResponseErrorHandler {
private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler();
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return errorHandler.hasError(response);
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
}
Application.java
package rentitnew;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
@Autowired
private WebMvcProperties mvcProperties = new WebMvcProperties();
@Autowired
Credentials credentials;
@Autowired
ClientHttpRequestFactory basicSecure;
@Bean
public RestTemplate restTemplate() {
RestTemplate _restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
_restTemplate.setMessageConverters(messageConverters);
_restTemplate.setErrorHandler(new CustomResponseErrorHandler());
_restTemplate.setRequestFactory(basicSecure);
return _restTemplate;
}
@Bean
public ClientHttpRequestFactory requestFactory() {
return new BasicSecureSimpleClientHttpRequestFactory();
}
@Bean
@ConfigurationProperties(locations = "classpath:META-INF/integration/credentials.yml")
public Credentials getCredentials() {
return new Credentials();
}
public static class Credentials {
private Map<String, Map<String, String>> credentials = new HashMap<>();
public Map<String, Map<String, String>> getCredentials() {
return this.credentials;
}
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rentitnew</groupId>
<artifactId>rentitnew</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rentitnew</name>
<description>Rentit Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.8</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.springtestdbunit</groupId>
<artifactId>spring-test-dbunit</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.16.0.RELEASE</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>rentitnew.Application</start-class>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<systemProperty>
<name>spring.profiles.active</name>
<value>production</value>
</systemProperty>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<reportsDirectory>shippable/testresults</reportsDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.7.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Procfile
web: java -Dserver.port=$PORT -Ddatabase.url=$DATABASE_URL $JAVA_OPTS -Dspring.profiles.active=production -jar target/*.jar
我可以提供一些建议,以便我可以更改代码/其他文件,以便我可以打开我的应用程序。 提前谢谢!
答案 0 :(得分:4)
好吧,我看到我还没有回答这个问题。所以尽管已经很晚了,但我会提供解决这个问题的方法。
除了Jens提出的更改之外,我在pom.xml
的插件标记中添加了以下插件。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
我意外地从pom.xml
删除了这个导致上述问题的插件。
答案 1 :(得分:2)
您错过了类路径中的org.springframework.web
。将它添加到你的pom中它应该可以工作。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version><!--your spring version--></version>
</dependency>
答案 2 :(得分:0)
就我而言,这仅适用于(适用于可执行jar文件):
插件:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
依赖性(与Jens答案相同):
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.10.RELEASE</version>
</dependency>
答案 3 :(得分:0)
尽管回答得很晚,但让我加2美分,对我来说,所有jar和build插件都在pom中,但是jar的作用域是“提供的”,因此尽管它在jar中运行,但并未通过我的IDE(intelliJ)曾经评论说一切正常。