2015-05-06 8 views
5

Impossibile avviare l'applicazione per il dropwizard dopo aver aggiunto i dettagli del database nel file di configurazione dell'applicazione (server.yml).* Campo non riconosciuto in: database Intendevi ?: - metrica - server - registrazione - DROPWIZARD

server.yml (file di configurazione app)

server: 
    applicationConnectors: 
    - type: http 
    port: 8080 
    adminConnectors: 
    - type: http 
    port: 9001 

database: 
    # the name of your JDBC driver 
    driverClass: org.postgresql.Driver 

    # the username 
    user: dbuser 

    # the password 
    password: pw123 

    # the JDBC URL 
    url: jdbc:postgresql://localhost/database 

    # any properties specific to your JDBC driver: 
    properties: 
    charSet: UTF-8 

    # the maximum amount of time to wait on an empty pool before throwing an exception 
    maxWaitForConnection: 1s 

    # the SQL query to run when validating a connection's liveness 
    validationQuery: "/* MyService Health Check */ SELECT 1" 

    # the timeout before a connection validation queries fail 
    validationQueryTimeout: 3s 

    # the minimum number of connections to keep open 
    minSize: 8 

    # the maximum number of connections to keep open 
    maxSize: 32 

    # whether or not idle connections should be validated 
    checkConnectionWhileIdle: false 

    # the amount of time to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing 
    evictionInterval: 10s 

    # the minimum amount of time an connection must sit idle in the pool before it is eligible for eviction 
    minIdleTime: 1 minute 

Come risultato di un'applicazione run dropwizard posso vedere:

has an error: 
    * Unrecognized field at: database 
    Did you mean?: 
     - metrics 
     - server 
     - logging 

risposta

9

nel file di configurazione di applicazioni Java, è necessario aggiungere il proprietà corrispondente per "database". Se le proprietà vengono specificate sono quelle standard, allora si può tenere con il tipo di DataSourceFactory (che sembrano essere, bene!):

public class ExampleConfiguration extends Configuration { 
    @Valid 
    @NotNull 
    @JsonProperty 
    private DataSourceFactory database = new DataSourceFactory(); 

    public DataSourceFactory getDataSourceFactory() { 
     return database; 
    } 

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

Esempio qui: http://www.dropwizard.io/0.9.0/docs/manual/jdbi.html

+0

Non ha funzionato per me :(ho già getter per i miei campi ancora affrontando il problema – RAJ

+1

Forse controllare la pagina di documentazione collegata? Le cose potrebbero essere cambiate da questa risposta ... Sembra che essi possono richiedere annotazioni JsonProperty ora (o forse l'esempio lo specifica) –

+0

Grazie, tuttavia, provato i documenti ma senza fortuna – RAJ

14

Oltre al codice dato per esempio dropwizard è necessario aggiungere un setter per la proprietà del database.

@Valid 
@NotNull 
@JsonProperty("database") 
private DataSourceFactory database = new DataSourceFactory(); 

public DataSourceFactory getDataSourceFactory() { 
    return database; 
} 

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

grazie, questo è stato difficile – vvondra

+1

grazie! ha funzionato, questa risposta dovrebbe essere contrassegnata come corretta –

+0

Sto avendo lo stesso errore, ma per la parte server di yml: "Campo non riconosciuto a: http" Come devo implementare le proprietà della classe di configurazione per questa parte? Grazie. – dushkin

Problemi correlati