java - Dropwizard:config.yml 有错误

标签 java yaml dropwizard

我对 Dropwizard 以及整个 JAVA 都很陌生。我尝试创建一个基本的 Dropwizard 项目(通过 Hibernate 与 MySQL 数据库连接)。我正在使用 Eclipse IDE 来实现同样的目的。我已按照 T 执行所有步骤,但在控制台中输入此命令后 -> java -jar target/hotel2-0.0.1-SNAPSHOT.jar server config.yml。我收到以下错误:-

config.yml has an error: 
* Failed to parse configuration at: logging; Can not instantiate value of type [simple type, class io.dropwizard.logging.LoggingFactory] from String value (''); no single-String constructor/factory method at [Source: N/A; line: -1, column: -1] (through reference chain: com.drivedge.hotel2.HotelMgntConfiguration["logging"])  

下面是我的 pom.xml 和 config.yml 文件的副本:

config.yml -

## Configuration file for Hotel2 application.
---
# User login.
logging:
login: javaeeeee
# User  password.
password: crimson

#Server configuration.
server:
    applicationConnectors:
        - type: http
          port: 9090
        - type: https
          port: 9090
          keyStorePath: hotel2.keystore
          keyStorePassword: crimson

# Database settings.
database:
    # the name of the JDBC driver, mysql in our case
    driverClass: com.mysql.jdbc.Driver
    # the username
    user: root
    # the password
    password: drivedge12
    # the JDBC URL; the database is called Hotel2
    url: jdbc:mysql://localhost:3306/hotelmanagement  

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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>

    <groupId>com.drivedge</groupId>
    <artifactId>hotel2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>HotelMgnt</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <dropwizard.version>0.8.2</dropwizard.version>
        <mainClass>com.drivedge.hotel2.HotelMgntApplication</mainClass>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-core</artifactId>
            <version>${dropwizard.version}</version>
        </dependency>
        <dependency>
            <groupId>io.dropwizard</groupId>
            <artifactId>dropwizard-hibernate</artifactId>
            <version>${dropwizard.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.5.1</version>
</dependency>
<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>javax.persistence</artifactId>
    <version>2.0.0</version>
    <scope>compile</scope>
</dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.7</version>
                <configuration>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>${mainClass}</mainClass>
                        </transformer>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                    </transformers>
                    <!-- exclude signed Manifests -->
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.8.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <reportPlugins>
                        <plugin>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.4</version>
                            <configuration>
                                <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                                <dependencyDetailsEnabled>false</dependencyDetailsEnabled>
                            </configuration>
                        </plugin>
                        <plugin>
                            <artifactId>maven-javadoc-plugin</artifactId>
                            <version>2.8.1</version>
                        </plugin>
                    </reportPlugins>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的配置文件:-

package com.drivedge.hotel2;

import io.dropwizard.Configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.db.DataSourceFactory;
import javax.validation.Valid;
import javax.validation.constraints.*;
//import org.apache.tomcat.jdbc.pool.DataSourceFactory;

public class HotelMgntConfiguration extends Configuration {
    /*// /**
    * A factory used to connect to a relational database management system.
    * Factories are used by Dropwizard to group together related configuration
    * parameters such as database connection driver, URI, password etc.
    */

   @NotNull
   @Valid
   @JsonProperty
   private DataSourceFactory database;

   /**
    * A getter for the database factory.
    *
    * @return An instance of database factory deserialized from the
    * configuration file passed as a command-line argument to the application.
    */

   public DataSourceFactory getDataSourceFactory() {
       return database;
   }

   public void setDatabase(DataSourceFactory database) {
        this.database = database;
    }
}

我哪里出错了?我对 Dropwizard 的东西真的很陌生。任何帮助将不胜感激!

最佳答案

从 config.yml 中删除 logging: 或像 example 那样配置日志记录.

关于java - Dropwizard:config.yml 有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41501829/

相关文章:

java - 准备语句执行批处理

java - Jenkins 在启动时失败并显示 "SEVERE: Error during context startup for webapp webapp"

amazon-web-services - 创建 SparkUI 历史服务器的 CF 模板失败

kubernetes - K8s 部署的插值

azure - azure 的 Ansible 库存插件抛出编码错误

eclipse - 如何让 Eclipse 在调试时正常关闭 dropwizard?

java - KeyBindings 和 KeyListeners 之间的区别

java - Dropwizard:如何以编程方式(进程内)关闭服务?

java - org.hibernate.AnnotationException : Use of @OneToMany or @ManyToMany targeting an unmapped class: core. user.User.userRole[core.user.UserRole]

具有多个具有不同签名的实现类的java接口(interface)