Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-1· AnthropicHugging Face Arena Human Preference 55K

create java micro service with spring boot reactive framework and connect with mongodb…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with guanaco-33b’s answer.
  1. User

    create java micro service with spring boot reactive framework and connect with mongodb database to fetch customer details including, customer id that is auto generated, customer name and customer age

  2. Claude Assistant

    Here is a Java microservice using Spring Boot Reactive and MongoDB:

    @SpringBootApplication
    public class CustomerServiceApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(CustomerServiceApplication.class, args);
    	}
    }
    
    @Repository
    public interface CustomerRepository extends ReactiveMongoRepository<Customer, String> {
    }
    
    @Entity
    public class Customer {
        @Id
        private String id;
        private String name;
        private int age;
        
        // Getters and setters
    }
    
    @RestController
    public class CustomerController {
        @Autowired
        private CustomerRepository repository;
        
        @GetMapping("/customers")
        public Flux<Customer> getAllCustomers() {
            return repository.findAll();
        }
        
        @GetMapping("/customers/{id}")
        public Mono<Customer> getCustomerById(@PathVariable String id) {
            return repository.findById(id);
        }
        
        @PostMapping("/customers")
        public Mono<Customer> saveCustomer(@RequestBody Customer customer) {
            return repository.save(customer);
        }
    }
    
    • The Customer entity has an auto-generated id, name and age
    • The CustomerRepository interface extends ReactiveMongoRepository to access MongoDB
    • The CustomerController has endpoints to get all customers, get by id, and save a new customer
    • It returns Flux/Mono reactive types from the endpoints
    • Spring Data MongoDB will generate the id automatically

    This service can be deployed as a Spring Boot microservice and will connect to MongoDB to store and retrieve customer data. Let me know if you have any other questions!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.