Java com.XXX中的字段需要找不到类型的bean

Java com.XXX中的字段需要找不到类型的bean,java,spring,hibernate,Java,Spring,Hibernate,我正在进行SpringOverHibernate项目,这只是一个开始。 我正在尝试拥有一个SpringBoot应用程序,它将一些LogEntries对象写入MsSql。 我有一些不同的套餐: 以下是课程: LogEntryFacadeImpl.class: package com.tradingSystem.dataAccess; import org.springframework.beans.factory.annotation.Autowired; import org.springf

我正在进行SpringOverHibernate项目,这只是一个开始。 我正在尝试拥有一个SpringBoot应用程序,它将一些LogEntries对象写入MsSql。 我有一些不同的套餐:

以下是课程:

LogEntryFacadeImpl.class:

package com.tradingSystem.dataAccess;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tradingSystem.entity.LogEntry;

@Service
public class LogEntryFacadeImpl implements LogEntryFacade{
    @Autowired
    private LogEntryDAO logEntryDao;

    @Transactional
    @Override
    public Long addLogEntry(LogEntry log) {
        return this.logEntryDao.save(log).getId();
    }

    @Override
    public LogEntry getLogEntry(Long logId) {
        return this.logEntryDao.findOne(logId);
    }
}
package com.tradingSystem.dataAccess;

import org.springframework.data.jpa.repository.JpaRepository;
import com.tradingSystem.entity.LogEntry;

public interface LogEntryDAO extends JpaRepository<LogEntry, Long> {

}
package com.testings;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import com.tradingSystem.dataAccess.LogEntryFacade;
import com.tradingSystem.entity.LogEntry;

@SpringBootApplication
@ComponentScan({"com.tradingSystem" })
public class TestApplication implements CommandLineRunner{
    @Autowired
    private LogEntryFacade logEntryFacade;



    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        LogEntry log = new LogEntry(552266, "Testing of log entry save", 
            new Date(System.currentTimeMillis()), 
            new Date(System.currentTimeMillis()));

        System.err.println(log);

        Long id = logEntryFacade.addLogEntry(log);

        LogEntry log2 = logEntryFacade.getLogEntry(id);

        System.err.println(log2);
    }



}
LogEntryDAO.class:

package com.tradingSystem.dataAccess;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tradingSystem.entity.LogEntry;

@Service
public class LogEntryFacadeImpl implements LogEntryFacade{
    @Autowired
    private LogEntryDAO logEntryDao;

    @Transactional
    @Override
    public Long addLogEntry(LogEntry log) {
        return this.logEntryDao.save(log).getId();
    }

    @Override
    public LogEntry getLogEntry(Long logId) {
        return this.logEntryDao.findOne(logId);
    }
}
package com.tradingSystem.dataAccess;

import org.springframework.data.jpa.repository.JpaRepository;
import com.tradingSystem.entity.LogEntry;

public interface LogEntryDAO extends JpaRepository<LogEntry, Long> {

}
package com.testings;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import com.tradingSystem.dataAccess.LogEntryFacade;
import com.tradingSystem.entity.LogEntry;

@SpringBootApplication
@ComponentScan({"com.tradingSystem" })
public class TestApplication implements CommandLineRunner{
    @Autowired
    private LogEntryFacade logEntryFacade;



    public static void main(String[] args) {
        SpringApplication.run(TestApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        LogEntry log = new LogEntry(552266, "Testing of log entry save", 
            new Date(System.currentTimeMillis()), 
            new Date(System.currentTimeMillis()));

        System.err.println(log);

        Long id = logEntryFacade.addLogEntry(log);

        LogEntry log2 = logEntryFacade.getLogEntry(id);

        System.err.println(log2);
    }



}
当我作为应用程序运行此应用程序时,我在控制台中收到以下消息:

应用程序无法启动

说明: com.tradingSystem.dataAccess.logentryfacadeinpl中的字段logEntryDao需要找不到“com.tradingSystem.dataAccess.logEntryDao”类型的bean。

行动:

考虑在配置中定义“com.tradingSystem.dataAccess.LogEntryDAO”类型的bean

如您所见,我将
@ComponentScan({“com.tradingSystem”})
注释放在测试仪中。然而,我仍然得到这个信息。 (当我没有使用任何软件包分离时,一切正常…)

请帮我解决这个问题


谢谢

您应该在存储库界面上方添加@Repository注释。
您可以选择添加它,如@Repository(value=“logEntryRepository”)

将您的主类放入com.tradingSystem包中。或者使用EnableJpaRepositories注释告诉存储库在哪里。@JBNizet谢谢。根据你的建议解决了这个问题。然而,我不明白为什么我不能把主目录放在com.tradingSystem.testing或com.testing下…你可以。但是,正如前面所说,您必须使用EnableJpaRepositories来告诉在哪里可以找到回购协议