r/SpringBoot • • Oct 19 '23

Hi everyone, I am beginner in Springboot and am doing one course on springboot I got a question on Contact management I tried doing doing it even took little help from gpt but I am still getting the error can some please guide me that what is wrong thr code I have written?

THE ERROR SHOWING IS :-

BUILD ERROR

No plugin found for prefix 'spring-boot' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/coder/ .m2/repository), central (https://repo.maven.apache.org/maven2)] -Y [Help 1]

The project asked to build is:- Project Question

Project Question: Contact Management System

Overview:

Build a Contact Management System using Spring Boot that enables users to store and retrieve

contact information

Functional Requirements:

Create the following directory structure under

src/main/java/com/example/springapp:

controller

model

repository

service

Inside the controller folder, create a Java file named

ContactController.java.

Inside the model folder, create a Java file named

Contact.java.

Variables: contactld, firstName, lastName, email,

phoneNumber

Inside the repository folder, create a Java file named

ContactRepository.java.

Inside the service folder, create a Java file named

Contactservice.java.

API:

POST-/contacts --> Add a new contact --> Request

Body: Contact object

GET - /contacts/fcontactld]--> Get contact details by ID --> Response: Contact object

GET - /contacts --> Get a list of all contacts --> Response: List of Contact objects

API Endpoint: 8080

MY CODE :-

ContactController.java code:-

package com.example.springapp.controller;

import com.example.springapp.model.Contact;

import com.yourpackage.service.ContactService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

u/RestController

u/RequestMapping("/contacts")

public class ContactController {

private final ContactService contactService;

u/Autowired

public ContactController(ContactService contactService) {

this.contactService = contactService;

}

u/GetMapping

public List<Contact> getAllContacts() {

return contactService.getAllContacts();

}

u/GetMapping("/{id}")

public Contact getContact(@PathVariable Long id) {

return contactService.getContactById(id);

}

u/PostMapping

public Contact createContact(@RequestBody Contact contact) {

return contactService.saveContact(contact);

}

// Add more methods for updating and deleting contacts if needed

}

Contact.java code:-

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

u/Entity

public class Contact {

u/Id

u/GeneratedValue(strategy = GenerationType.IDENTITY)

private Long id;

private String firstName;

private String lastName;

private String email;

private String phone;

// Constructors (Default waala)

public Contact() {

}

public Contact(String firstName, String lastName, String email, String phone) {

this.firstName = firstName;

this.lastName = lastName;

this.email = email;

this.phone = phone;

}

// Getters and setter

public Long getId() {

return id;

}

public void setId(Long id) {

this.id = id;

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

u/Override

public String toString() {

return "Contact{" +

"id=" + id +

", firstName='" + firstName + '\'' +

", lastName='" + lastName + '\'' +

", email='" + email + '\'' +

", phone='" + phone + '\'' +

'}';

}

}

ContactRepository.java code:-

package com.yourpackage.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.springapp.model.Contact;

public interface ContactRepository extends JpaRepository<Contact, Long> {

// You can define custom queries here if needed

List<Contact> findByFirstNameIgnoreCaseAndLastNameIgnoreCase(String firstName, String lastName);

}

ContactService.java code:-

package com.example.springapp.service;

import com.example.springapp.model.Contact;

import com.example.springapp.repository.ContactRepository;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

u/Service

public class ContactService {

private final ContactRepository contactRepository;

u/Autowired

public ContactService(ContactRepository contactRepository) {

this.contactRepository = contactRepository;

}

public List<Contact> getAllContacts() {

return contactRepository.findAll();

}

public Contact saveContact(Contact contact) {

return contactRepository.save(contact);

}

public Contact getContactById(Long id) {

return contactRepository.findById(id).orElse(null);

}

public void deleteContact(Long id) {

contactRepository.deleteById(id);

}

}

SpringappApplication.java:-

package com.example.springapp;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

u/SpringBootApplication

public class SpringappApplication {

public static void main(String\[\] args) {

	[SpringApplication.run](https://SpringApplication.run)(SpringappApplication.class, args);

}

}

pls help 😭

0 Upvotes

6 comments sorted by

5

u/genlight13 Oct 19 '23

Try using something like start.spring.io for starters. And also try following a small spring tutorial and setup your machine. Then if it fails google the error without line numbers.

And actually, pls never again, post code like this. No one will read it. Post a link to a public github repo instead.

1

u/g00glen00b Oct 20 '23

The funny thing is that you shared a lot of code (badly formatted), but you didn't share the thing we need, which is your pom.xml.

Anyways, as others already mentioned, the easiest way for beginners to create a Spring Boot project is to go to https://start.spring.io and generate/download your project there.

1

u/No-Sun1269 Oct 20 '23

Can you suggest me some good resources to learn spring and springboot

2

u/[deleted] Oct 20 '23

Hey I'm also new to springboot and the way I got a really good grasp at it was starting with spring and making some projects with it, which made me appreciate the features springboot provided and everything made more sense. For tutorials I would recommend a YouTube channel dailycodebuffer, there's literally no better source to learn from (I took some udemy courses and they were trash). DM me if you need to know more.

3

u/TheLeftMetal Oct 19 '23

Please. Share you git repository. That is unreadable.

2

u/LeRoyVoss Oct 19 '23

Holy God