0
votes

I want to create delete row SQL, but when i run my project, i have error, org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactUsRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.oop2.contactus.model.ContactForm

this my code

ContactUsList.html

<a th:href="@{'/delete-contact-us/'+ ${contactForm.id}}">Delete</a>

MainController.java

@RequestMapping("/delete-contact-us/{id}")
    public String deleteContactUs(@PathVariable(name = "id") int id) {
       contactService.delete(id);
       return "ContactUsList";
}

ContactService.java

public void delete(long id) {
    contactRepository.deleteById(id);
}

ContactUsRepository.java

package com.oop2.contactus.repositories;
import com.oop2.contactus.model.ContactForm;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ContactUsRepository extends CrudRepository<ContactForm, Long> {
}
1
The exception is telling you what is wrong. -> Not a managed type: class com.oop2.contactus.model.ContactForm. Which means ContactForm isn't an entity. So either you are using the wrong type, or your packages aren't scanned correctly (like your @SpringBootApplication class should be in the com.oop2 package. - M. Deinum

1 Answers

0
votes

I suppose that spring can't find ContactForm because it's not in the default package. Check that :

Autowiring fails: Not an managed Type

And

Spring boot - Not an managed type