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

标签 java hibernate dropwizard

我正在使用 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/

相关文章:

java - 为什么 Gradle 会解析版本号错误的包?

java - 在 dropwizard 资源类中使用 jdbi sql 接口(interface)

java - 在 servlet 容器启动后立即调用对 localhost 的请求

java - SQL异常 : this driver is not configured for integrated authentication tomcat

java - 对动态代理的调用应该转到动态类型的方法还是静态类型的方法?

mysql - Json响应与数据库数据不匹配

java - 与 Hibernate 一对一关系,提交 JSP 表单时出现共享 key 错误

java - 如何使用 QueryBuilder、Lucene Query 和 FullTextQuery 显示 hibernate 搜索结果?

java - "java: No match."是什么意思?

java - Swagger Dropwizard 0.7 - 不显示 JSON 参数的 TextArea