2012-11-12 36 views
14

Looking for a dụ dropwizard tôi thấy:Looking for a dụ dropwizard

https://github.com/codahale/dropwizard/tree/master/dropwizard-example

Nhưng tôi quan tâm đến một ví dụ hoàn chỉnh hơn với ít nhất:

  1. 1: n mối quan hệ như khách hàng - tài khoản
  2. repienation html gui ít nhất với các biểu mẫu
  3. hỗ trợ đầy đủ crud cho xml

2 trong số ba sẽ là bắt đầu và sẽ kiếm được "chấp nhận" bởi tôi.

+1

gì đã làm * bạn * cố gắng để kiếm được câu trả lời cho câu hỏi này? –

+3

Tôi đang trong quá trình tự chuẩn bị câu trả lời vì tôi nghĩ cần có câu trả lời. Nếu không ai trả lời tôi sẽ trình bày một. –

+1

Bạn có thể giải quyết vấn đề này không? –

Trả lời

19

Hãy xem một số của tôi Dropwzard projects

Đặc biệt là MultiBit Merchant dự án (Admin, Store và Platform) sẽ cung cấp cho bạn một sự giàu có của mã trình diễn cho thấy làm thế nào để có được công cụ thực hiện trong Dropwizard. Ngoài ra còn có một ví dụ về OpenID với Dropwizard nên cung cấp một điểm khởi đầu tốt cho một ứng dụng mới.

Tất cả đều là FOSS theo giấy phép MIT.

2

tôi đã viết một ví dụ trong dự án Dropwizard XML Bundle tôi:

https://github.com/yunspace/dropwizard-xml/tree/master/dropwizard-xml-example

Đó có lẽ là gần nhất với những gì bạn đang tìm kiếm. Nó có:

  • 1: N mối quan hệ giữa Pirates và Ships, được lưu trữ trong H2 db.
  • Hỗ trợ CRUD đầy đủ cho XML bằng cách sử dụng JacksonMessageBodyProvider tùy chỉnh có xác thực.

Thêm gui HTML qua mẫu Freemarker hoặc Mustache phải khá nhỏ và được đề cập trong tài liệu chuẩn.

7

Wolfgang,

đây là một example Dropwizard application nơi Authentication, cấu hình và truy cập cơ sở dữ liệu sử dụng Hibernate được sử dụng.

Ứng dụng này sẽ được thảo luận trong một vài hướng dẫn:

here là một ví dụ khác, nơi người ta có thể lưu trữ bookmark cho chứng thực bạn sers và truy cập dữ liệu thông qua REST API.

Chúc may mắn.

-1

làm theo bước dưới đây.

  1. Thêm phụ thuộc trong tập tin pom

    <dependencies> 
    <dependency> 
        <groupId>com.yammer.dropwizard</groupId> 
        <artifactId>dropwizard-core</artifactId> 
        <version>0.6.2</version> 
    </dependency> 
    

  2. Tạo cấu hình lớp

    import com.yammer.dropwizard.config.Configuration; 
    public class BlogConfiguration extends Configuration{ 
    
    } 
    
  3. Tạo lớp Service

    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()); 
        } 
    
        } 
    

Lưu ý: đặt bên dưới tập tin trong thư mục hiện configuration.yml

 # 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. nguồn Viết Index.

 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; 
    } 


    } 
  1. Viết POJO cho Blog và người sử dụng như

    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 + "]"; 
    } 
    
  2. Run BlogService mà sẽ khởi động server Jetty và nhấn localhost với cổng như http://localhost:8079/

0

Bạn có thể thử dự án này từ Github.

Dropwizard: hoạt động CRUD, xem HTML, Healthcheck

https://github.com/HoldInArms/dropwizard-mssql-crud-example

+0

Ví dụ tốt nhưng mã trên dường như sử dụng phiên bản cũ của dropwizard. Cùng một mã được chuyển đến Mysql với phiên bản dropwizard 1.0.5 - https://github.com/rahulsh1/dropwizard-mysql-crud-example – Neo

Các vấn đề liên quan