【问题标题】:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactUsRepository':org.springframework.beans.factory.BeanCreationException:创建名为“contactUsRepository”的bean时出错:
【发布时间】:2020-10-20 12:36:46
【问题描述】:

我想创建删除行 SQL,但是当我运行我的项目时,我有错误, org.springframework.beans.factory.BeanCreationException:创建名为“contactUsRepository”的bean时出错:FactoryBean在创建对象时抛出异常;嵌套异常是 java.lang.IllegalArgumentException: Not a managed type: class 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> {
}

【问题讨论】:

  • 异常告诉你哪里出了问题。 ->Not a managed type: class com.oop2.contactus.model.ContactForm。这意味着ContactForm 不是一个实体。所以要么你使用了错误的类型,要么你的包没有被正确扫描(比如你的@SpringBootApplication类应该在com.oop2包中。

标签: java mysql spring thymeleaf


【解决方案1】:

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

Autowiring fails: Not an managed Type

Spring boot - Not an managed type

【讨论】:

    猜你喜欢
    • 2016-06-05
    • 2020-02-21
    • 2018-04-27
    • 2020-11-04
    • 2021-11-11
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多