org.springframework.beans.factory.BeanCreationException:创建名称为“ contactUsRepository”的bean时出错:

时间:2020-06-30 08:41:44

标签: java mysql spring thymeleaf

我想创建删除行SQL,但是当我运行项目时,出现错误, org.springframework.beans.factory.BeanCreationException:创建名称为“ contactUsRepository”的bean时出错:FactoryBean在对象创建时抛出异常;嵌套异常是java.lang.IllegalArgumentException:不是托管类型:com.oop2.contactus.model.ContactForm类

这是我的代码

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 个答案:

答案 0 :(得分:0)

我认为spring找不到ContactForm,因为它不在默认包中。 检查:

Autowiring fails: Not an managed Type

Spring boot - Not an managed type