我正在使用hibernate在Drop Wizard上创建一个Web服务,但是我收到了这个错误
@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)
堆栈跟踪:
strpos
答案 0 :(得分:2)
最近我自己也遇到了这个问题。问题是我使用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>