Dropwizard:config.yml有错误

时间:2017-01-06 08:35:09

标签: 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的东西都很陌生。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:2)

从config.yml中删除logging:或配置example中的日志记录。