问题
Looking for a dropwizard example I found:
https://github.com/codahale/dropwizard/tree/master/dropwizard-example
But I am interested in a more complete example with at least:
- a 1:n relationship like customer - account
- a html gui represenation at least with forms
- full crud support for xml
2 out of three would be a start and would earn "accepted" by me.
回答1:
Take a look at some of my Dropwzard projects
In particular the MultiBit Merchant projects (Admin, Store and Platform) will provide you with a wealth of demonstration code that shows how to get stuff done in Dropwizard. There is also an example of OpenID with Dropwizard that should provide a good launch point for a new application.
They are all FOSS under the MIT license.
回答2:
Wolfgang,
here is an example Dropwizard application where Authentication, Configuration and database access using Hibernate are used.
The application is discussed in several tutorials:
- First Steps
- Authentication, Configuration and HTTPS
- Connecting to a Database using Hibernate
- Connecting to external REST Web-services using Jersey Client
And here is another example, where one can store bookmarks for authenticated users and access data via REST API.
Good luck.
回答3:
That looks like a nice example as well: https://github.com/spinscale/dropwizard-blog-sample
回答4:
I wrote an example in my Dropwizard XML Bundle project:
https://github.com/yunspace/dropwizard-xml/tree/master/dropwizard-xml-example
It's probably the closest to what you are looking for. It has:
- 1:N relationship between Pirates and Ships, stored in a H2 db.
- Full CRUD support for XML using custom JacksonMessageBodyProvider with validation.
Adding HTML gui via Freemarker or Mustache templates should be pretty trivial and is covered in the standard docs.
回答5:
A good example who want dropwizard with authentication.
Dropwizard: Authentication, Configuration and HTTPS https://dzone.com/articles/getting-started-dropwizard-0
回答6:
You can try this project from Github.
Dropwizard: CRUD operation, HTML views, Healthcheck
https://github.com/HoldInArms/dropwizard-mssql-crud-example
回答7:
follow below step.
Add dependencies in pom file
<dependencies> <dependency> <groupId>com.yammer.dropwizard</groupId> <artifactId>dropwizard-core</artifactId> <version>0.6.2</version> </dependency>Create configuration class
import com.yammer.dropwizard.config.Configuration; public class BlogConfiguration extends Configuration{ }Create Service class
import com.yammer.dropwizard.Service; import com.yammer.dropwizard.config.Bootstrap; import com.yammer.dropwizard.config.Environment; public class BlogService extends Service<BlogConfiguration> { public static void main(String[] args) throws Exception { new BlogService().run(new String[] { "server", "C:\\LocalEnv\\Workspace\\dropwizarddemo\\configuration.yml" }); } @Override public void initialize(Bootstrap<BlogConfiguration> bootstrap) { bootstrap.setName("blog"); } @Override public void run(BlogConfiguration configuration, Environment environment) throws Exception { environment.addResource(new IndexResource()); } }
Note: put below configuration.yml file in current directory
# HTTP-specific options.
http:
# The port on which the HTTP server listens for service requests.
port: 8079
# The port on which the HTTP server listens for administrative
# requests.
adminPort: 8179
# Maximum number of threads.
maxThreads: 100
# Minimum number of thread to keep alive.
minThreads: 10
4. Write Index resources.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.yammer.metrics.annotation.Timed;
@Path("/")
public class IndexResource {
@GET
@Produces(value = MediaType.APPLICATION_JSON)
@Timed
public List<Blog> index() {
return Arrays.asList(new Blog("for Java Developers",
"http://stackoverflow.com/questions/13345693/looking-for-a-dropwizard-
example”));
}
@Path("/service")
@GET
@Produces(value = MediaType.APPLICATION_JSON)
@Timed
public List<Users> users() {
List<Users> list = new ArrayList<Users>();
list.add(new Users(25,"Sambhu","SA"));
list.add(new Users(35,"Amit","VP"));
list.add(new Users(45,"Sanket","AVP"));
return list;
}
}
Write POJO for Blog and Users like
public class Users { Integer id; String name; String designation; public Users(Integer id, String name, String desination){ this.id=id; this.name=name; this.designation=desination; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDesignation() { return designation; } public void setDesignation(String designation) { this.designation = designation; } @Override public String toString() { return "Users [id=" + id + ", name=" + name + ", designation=" + designation + "]"; }Run BlogService which will start the Jetty server and hit the localhost with port such as http://localhost:8079/
来源:https://stackoverflow.com/questions/13345693/looking-for-a-dropwizard-example