gpt4 book ai didi

java - 错误 java.lang.NoSuchMethodError : io. dropwizard.setup.Environment.getHealthCheckExecutorService()

转载 作者:行者123 更新时间:2023-11-30 03:18:10 25 4
gpt4 key购买 nike

我正在使用 hibernate 在 Drop Wizard 上创建一个 Web 服务,但收到此错误

private final HibernateBundle<RestStubConfig> hibernate = new HibernateBundle<RestStubConfig>(Hotel.class) {
public DataSourceFactory getDataSourceFactory(RestStubConfig configuration) {
return configuration.getDataSourceFactory();
}
};

public static void main(String[] args) throws Exception {
new ServerStart().run(args);
}

@Override
public void run(RestStubConfig restConf, Environment env) throws Exception {
final HotelResource hotel = new HotelResource();
env.jersey().register(hotel);
}

@Override
public void initialize(Bootstrap<RestStubConfig> bootstrap) {
bootstrap.addBundle(hibernate);
}

我的对象类

@Entity
@Table(name="hotel")
public class Hotel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private int DpId;
private String timestamp;
private String hotelName;
private String email;
private String phone;
private String address;
private String geoLocation;
// Must have no-argument constructor
public Hotel() {
this.hotelName = null;
this.email = null;
this.phone = null;
this.address = null;
this.geoLocation = null;
this.id =8009;
this.DpId=0;
this.timestamp = null;
}
public Hotel(String hotelName, String email, String phone, String address, String geoLocation) {
this.id = 8009;
this.hotelName = hotelName;
this.email = email;
this.phone = phone;
this.address = address;
this.geoLocation = geoLocation;
this.timestamp = null;
}
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getGeoLocation() {
return geoLocation;
}
public void setGeoLocation(String geoLocation) {
this.geoLocation = geoLocation;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getDpId() {
return DpId;
}
public void setDpId(int dpId) {
DpId = dpId;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
@Override
public String toString() {
return new StringBuffer(" ID ").append(this.id).append(" Hotel Name : ").append(this.hotelName).append(" Email : ").append(this.email)
.append(" Phone : ").append(this.phone).append(" GeoLocation : ").append(this.geoLocation).append(" TimeStamp : ").append(this.timestamp).toString();
}

我的配置类是

public class RestStubConfig extends Configuration {
@NotEmpty
private String version;
@Valid
@NotNull
@JsonProperty("database")
private DataSourceFactory database = new DataSourceFactory();
@JsonProperty
public String getVersion() {
return version;
}
@JsonProperty
public void setVersion(String version) {
this.version = version;
}
public DataSourceFactory getDataSourceFactory() {
return database;
}

堆栈跟踪:

Exception in thread "main" java.lang.NoSuchMethodError: io.dropwizard.setup.Environment.getHealthCheckExecutorService()Ljava/util/concurrent/ExecutorService;
at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:60)
at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:14)
at io.dropwizard.setup.Bootstrap.run(Bootstrap.java:183)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:41)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
at io.dropwizard.cli.Cli.run(Cli.java:70)
at io.dropwizard.Application.run(Application.java:73)
at com.quinchy.startUp.ServerStart.main(ServerStart.java:21)

最佳答案

最近我自己也遇到了这个。该问题是我使用 maven 导入的库的 dropwizard-core (0.8.0) 版本和 dropwizard-hibernate (0.8.2) 版本之间不匹配。

如果您确保使用两个库的 0.8.2 版本,这应该可以解决此问题。

<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.8.2</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
<version>0.8.2</version>
</dependency>

关于java - 错误 java.lang.NoSuchMethodError : io. dropwizard.setup.Environment.getHealthCheckExecutorService(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32023664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com