我有一个项目使用最新的spring 5,最新的hibernate 5.我在一个bean中使用@Async @Scheduled(fixedDelay = 500)注释了一个方法 . 这个函数的主体是空的:

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
@Component
public class SchedulerBean implements Serializable {

  private transient static final Logger LOG = LogManager.getLogger();

  @PersistenceContext(type = PersistenceContextType.TRANSACTION)
  private EntityManager entityManager;

  @Async
  @Scheduled(fixedDelay = 500)
  public void spoolerSender() {
  }
}

每次运行此方法时,即使现在为空,它也会查询数据库,这里是查询日志的转储:

+----------------------------+------------------------------------+-----------+-----------+--------------+---------------------------------------------------------------------------------------+
| event_time                 | user_host                          | thread_id | server_id | command_type | argument                                                                              |
+----------------------------+------------------------------------+-----------+-----------+--------------+---------------------------------------------------------------------------------------+
| 2018-06-13 15:03:48.185014 | root[root] @ localhost []          |     39544 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:48.281757 | [root] @ localhost [127.0.0.1]     |     39545 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:48.281951 | root[root] @ localhost [127.0.0.1] |     39545 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:48.282080 | root[root] @ localhost [127.0.0.1] |     39545 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:48.282473 | root[root] @ localhost [127.0.0.1] |     39545 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:48.282875 | root[root] @ localhost [127.0.0.1] |     39545 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:48.283170 | root[root] @ localhost [127.0.0.1] |     39545 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:48.782109 | [root] @ localhost [127.0.0.1]     |     39546 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:48.782307 | root[root] @ localhost [127.0.0.1] |     39546 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:48.782438 | root[root] @ localhost [127.0.0.1] |     39546 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:48.782881 | root[root] @ localhost [127.0.0.1] |     39546 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:48.783379 | root[root] @ localhost [127.0.0.1] |     39546 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:48.783855 | root[root] @ localhost [127.0.0.1] |     39546 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:49.283183 | [root] @ localhost [127.0.0.1]     |     39547 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:49.283513 | root[root] @ localhost [127.0.0.1] |     39547 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:49.283687 | root[root] @ localhost [127.0.0.1] |     39547 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:49.284119 | root[root] @ localhost [127.0.0.1] |     39547 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:49.284678 | root[root] @ localhost [127.0.0.1] |     39547 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:49.285206 | root[root] @ localhost [127.0.0.1] |     39547 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:49.783007 | [root] @ localhost [127.0.0.1]     |     39548 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:49.783202 | root[root] @ localhost [127.0.0.1] |     39548 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:49.783377 | root[root] @ localhost [127.0.0.1] |     39548 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:49.783758 | root[root] @ localhost [127.0.0.1] |     39548 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:49.784199 | root[root] @ localhost [127.0.0.1] |     39548 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:49.784719 | root[root] @ localhost [127.0.0.1] |     39548 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:50.283336 | [root] @ localhost [127.0.0.1]     |     39549 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:50.283520 | root[root] @ localhost [127.0.0.1] |     39549 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:50.283740 | root[root] @ localhost [127.0.0.1] |     39549 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:50.284145 | root[root] @ localhost [127.0.0.1] |     39549 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:50.284600 | root[root] @ localhost [127.0.0.1] |     39549 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:50.284939 | root[root] @ localhost [127.0.0.1] |     39549 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:50.784405 | [root] @ localhost [127.0.0.1]     |     39550 |         0 | Connect      | root@localhost as anonymous on hibernate_test                                         |
| 2018-06-13 15:03:50.784703 | root[root] @ localhost [127.0.0.1] |     39550 |         0 | Query        | set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')                |
| 2018-06-13 15:03:50.784955 | root[root] @ localhost [127.0.0.1] |     39550 |         0 | Query        | SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment |
| 2018-06-13 15:03:50.785599 | root[root] @ localhost [127.0.0.1] |     39550 |         0 | Query        | set autocommit=0                                                                      |
| 2018-06-13 15:03:50.786197 | root[root] @ localhost [127.0.0.1] |     39550 |         0 | Query        | set autocommit=1                                                                      |
| 2018-06-13 15:03:50.786582 | root[root] @ localhost [127.0.0.1] |     39550 |         0 | Quit         |                                                                                       |
| 2018-06-13 15:03:51.141919 | [root] @ localhost []              |     39551 |         0 | Connect      | root@localhost as anonymous on                                                        |
| 2018-06-13 15:03:51.142045 | root[root] @ localhost []          |     39551 |         0 | Query        | select @@version_comment limit 1                                                      |
| 2018-06-13 15:03:51.142223 | root[root] @ localhost []          |     39551 |         0 | Query        | SET GLOBAL general_log="OFF"                                                          |
+----------------------------+------------------------------------+-----------+-----------+--------------+---------------------------------------------------------------------------------------+

这是因为EntityManager和/或Transactional发生的吗?这个类不应该只实例化一次吗?