Autowiring fails: Not an managed Type

前端 未结 13 1969
清酒与你
清酒与你 2020-12-02 12:30

I have a big problem in my diploma project and would be very glad if you guys could help me! I made a Maven Multi Module Project and have 3 \"Core-projects\"

  • <
相关标签:
13条回答
  • 2020-12-02 12:43

    You should extend the scope of the component-scan e.g. <context:component-scan base-package="at.naviclean" /> since you placed the entities in package at.naviclean.domain;

    This should help you to get rid the exeption: Not an managed type: class at.naviclean.domain.Kassa

    For further debugging you could try to dump the application context (see javadoc) to explore which classes have been detected by the component-scan if some are still no recognized check their annotation (@Service, @Component etc.)

    EDIT:

    You also need to add the classes to your persistence.xml

    <persistence-unit>
        <class>at.naviclean.domain.Kassa</class>
         ...
    </persistence-unit>
    
    0 讨论(0)
  • 2020-12-02 12:46

    For me the error was quite simple based on what @alfred_m said..... tomcat had 2 jars conflicting having same set of Class names and configuration.

    What happened was ..............I copied my existing project to make a new project out of the existing project. but without making required changes, I started working on other project. Henec 2 projects had same classes and configuration files, resulting into conflict.

    Deleted the copied project and things started working!!!!

    0 讨论(0)
  • 2020-12-02 12:46

    You get the same exception when you pass the incorrect Entity object to the CrudRepository in the repository class.

    public interface XYZRepository extends CrudRepository<IncorrectEntityClass, Long>
    
    0 讨论(0)
  • 2020-12-02 12:50

    After encountering this issue and tried different method of adding the entity packaname name to EntityScan, ComponentScan etc, none of it worked.

    Added the package to packageScan config in the EntityManagerFactory of the repository config. The below code gives the code based configuration as opposed to XML based ones answered above.

    @Primary
    @Bean(name = "entityManagerFactory")
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(dataSource);
        emf.setJpaVendorAdapter(jpaVendorAdapter);
        emf.setPackagesToScan("org.package.entity");
        emf.setPersistenceUnitName("default"); 
        emf.afterPropertiesSet();
        return emf.getObject();
    }
    
    0 讨论(0)
  • 2020-12-02 12:50

    Refering to Oliver Gierke's hint:

    When the manipulation of the persistance.xml does the trick, then you created a normal java-class instead of a entity-class.

    When creating a new entity-class then the entry in the persistance.xml should be set by Netbeans (in my case).

    But as mentioned by Oliver Gierke you can add the entry later to the persistance.xml (if you created a normal java-class).

    0 讨论(0)
  • 2020-12-02 12:55

    When you extend indirectly JpaRepository ( KassaRepository extends BaseRepository that extends JpaRepository) then you have to annotate BaseRepository with @NoRepositoryBean :

    @NoRepositoryBean
    public interface BaseRepository<T extends ModelBase> extends JpaRepository<T, Long> {
        T findById(long id);
    }
    
    0 讨论(0)
提交回复
热议问题