Spring Boot不会初始化Ehcache

列夫

我正在使用Spring Boot和Ehcache开发一个项目。

当我使用Junit执行该项目的一种方法时,我看到Ehcache已完全初始化。

20:08:27.346 [main] INFO org.springframework.cache.ehcache.EhCacheManagerFactoryBean - Initializing EhCache CacheManager
20:08:27.348 [main] DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
20:08:27.361 [main] DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xmlns:xsi
20:08:27.362 [main] DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
20:08:27.363 [main] DEBUG net.sf.ehcache.config.DiskStoreConfiguration - Disk Store Path: C:\TEMP\
20:08:27.378 [main] DEBUG net.sf.ehcache.CacheManager - Creating new CacheManager with Configuration Object
20:08:27.379 [main] DEBUG net.sf.ehcache.util.PropertyUtil - propertiesString is null.
20:08:27.388 [main] DEBUG net.sf.ehcache.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
20:08:27.437 [main] DEBUG net.sf.ehcache.Cache - No BootstrapCacheLoaderFactory class specified. Skipping...
20:08:27.437 [main] DEBUG net.sf.ehcache.Cache - CacheWriter factory not configured. Skipping...
20:08:27.437 [main] DEBUG net.sf.ehcache.config.ConfigurationHelper - No CacheExceptionHandlerFactory class specified. Skipping...
20:08:27.451 [main] DEBUG net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.MemoryStore for rrr1
20:08:27.476 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
20:08:27.476 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
20:08:27.476 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE
20:08:27.476 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LOCAL_DISK_SIZE_BYTES
20:08:27.477 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
20:08:27.477 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: REMOTE_SIZE
20:08:27.477 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
20:08:27.487 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: OFFHEAP_GET
20:08:27.487 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: OFFHEAP_PUT
20:08:27.487 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: OFFHEAP_REMOVE
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: DISK_GET
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: DISK_PUT
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: DISK_REMOVE
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: XA_COMMIT
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: XA_ROLLBACK
20:08:27.488 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: XA_RECOVERY
20:08:27.489 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: CLUSTER_EVENT
20:08:27.489 [main] DEBUG net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl - Mocking Operation Statistic: NONSTOP
20:08:27.495 [main] DEBUG net.sf.ehcache.Cache - Initialised cache: rrr1
20:08:27.495 [main] DEBUG net.sf.ehcache.config.ConfigurationHelper - CacheDecoratorFactory not configured. Skipping for 'rrr1'.
20:08:27.495 [main] DEBUG net.sf.ehcache.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'rrr1'.

但是,当我将Spring Boot用于同一项目时,我看不到Ehcahe完全初始化的代码。

2016-08-09 20:01:20.532  INFO 20200 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: JpaPersistenceUnit
    ...]
2016-08-09 20:01:20.599  INFO 20200 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.1.0.Final}
2016-08-09 20:01:20.601  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2016-08-09 20:01:20.602  INFO 20200 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2016-08-09 20:01:20.733  INFO 20200 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-08-09 20:01:21.014  INFO 20200 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2016-08-09 20:01:21.904  INFO 20200 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'JpaPersistenceUnit'
2016-08-09 20:01:22.185  INFO 20200 --- [           main] o.s.c.ehcache.EhCacheManagerFactoryBean  : Initializing EhCache CacheManager
2016-08-09 20:01:22.803  INFO 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@515c6049: startup date [Tue Aug 09 20:01:17 NOVT 2016]; root of context hierarchy
2016-08-09 20:01:22.879 DEBUG 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking for request mappings in application context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@515c6049: startup date [Tue Aug 09 20:01:17 NOVT 2016]; root of context hierarchy
2016-08-09 20:01:22.891 DEBUG 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 1 request handler methods found on class com.ric.web.GreetingController: {public java.lang.String com.ric.web.GreetingController.greeting(java.lang.String)={[/greeting]}}
2016-08-09 20:01:22.891  INFO 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting]}" onto public java.lang.String com.ric.web.GreetingController.greeting(java.lang.String)
2016-08-09 20:01:22.894 DEBUG 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 request handler methods found on class org.springframework.boot.autoconfigure.web.BasicErrorController: {public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)={[/error]}, public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)={[/error],produces=[text/html]}}
2016-08-09 20:01:22.895  INFO 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-08-09 20:01:22.895  INFO 20200 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-08-09 20:01:22.945 DEBUG 20200 --- [           main] o.s.w.s.h.BeanNameUrlHandlerMapping      :

当我使用Spring Boot时,看不到带有统计信息的任何行:LOCAL_OFFHEAP_SIZE_BYTES统计信息:LOCAL_DISK_SIZE统计信息:LOCAL_DISK_SIZE_BYTES

此外,我没有看到缓存的磁盘存储路径,如第一个示例:DiskStoreConfiguration-磁盘存储路径:C:\ TEMP \

每次执行的日志记录设置都相同。

为什么会发生?

弹簧启动模块:

AppConfig.java:

@Configuration
@ComponentScan({"com.ric.bill"})
@ImportResource("spring.xml")
@EnableCaching
public class AppConfig {



}

BillWebApplication.java:

@SpringBootApplication
@EnableCaching
public class BillWebApplication {

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

Ehcache.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd">


    <diskStore path="java.io.tmpdir"/>

    <cache name="rrr1"
       maxElementsInMemory="500000" 
       eternal="true" 
       overflowToDisk="false" 
       memoryStoreEvictionPolicy="LRU">
    </cache>

</ehcache>

application.properties:

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: INFO

log4j.properties:

log4j.rootLogger=info, console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

spring.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">

    <!-- *******************************
         ***** CACHE CONFIGURATION ***** 
         ******************************* -->                
        <cache:annotation-driven  cache-manager="cacheManager" />

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcache"/>
    </bean>
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:ehcache.xml"/>
        <property name="shared" value="true"/>
    </bean> 

    <bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close"> 
          <property name="URL" value="jdbc:oracle:thin:@192.168.100.92:1521:DEVDB" /> 
          <property name="user" value="lev"/> 
          <property name="password" value="testtest1"/> 
          <property name="connectionCachingEnabled" value="true"/> 
    </bean>

    <bean
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        id="entityManagerFactory">
        <property name="dataSource" ref="dataSource" />
    </bean>

     <context:component-scan base-package="com.ric.bill" />
     <context:component-scan base-package="com.ric.bill.dao.impl" />
     <context:component-scan base-package="com.ric.bill.mm.impl" />


    <bean class="org.springframework.orm.jpa.JpaTransactionManager"
        id="transactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

 <tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/>

    <context:spring-configured />
    <context:annotation-config />


</beans>
安迪·威尔金森(Andy Wilkinson)

每次执行的日志设置都相同

输出的不同格式告诉我事实并非如此。

默认情况下,单元测试将DEBUG用作根日志记录级别,在启动Spring Boot应用程序时,默认的日志记录级别为INFO加上您在中进行的任何自定义application.properties例如,org.springframework.web由于您的配置,您可以查看DEBUG消息

如果您想在启动应用程序时查看来自EhCache的DEBUG消息,请更新以下内容application.properties

logging.level.org.springframework.web: DEBUG
logging.level.org.hibernate: INFO
logging.level.net.sf.ehcache: DEBUG

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spring Boot JPA模式初始化

来自分类Dev

Spring Boot 并初始化 sessionFactory

来自分类Dev

在Spring Boot启动时初始化表

来自分类Dev

在Spring Boot测试之前初始化数据库

来自分类Dev

Spring-Boot-jdbcTemplate对象未初始化

来自分类Dev

Spring Boot重启时如何防止db初始化

来自分类Dev

Spring Boot:无法初始化PostgreSQL数据源

来自分类Dev

如何使用spring-boot初始化ActiveMQ的SystemUsage?

来自分类Dev

使用RabbitMQ的Spring Boot无法初始化

来自分类Dev

Spring Boot 中的上下文初始化问题

来自分类Dev

无法从 Spring Boot 初始化 servlet 的 init 方法

来自分类Dev

使用Spring Security初始化应用程序时出错:找不到net / sf / ehcache / Ehcache

来自分类Dev

Spring的初始化方法

来自分类Dev

登录Spring初始化

来自分类Dev

Spring如何初始化多个数据源(不带Spring Boot)

来自分类Dev

Spring如何初始化多个数据源(不带Spring Boot)

来自分类Dev

Spring Context初始化(java)

来自分类Dev

Spring中的条件类初始化

来自分类Dev

了解Spring Dispatcher Servlet初始化

来自分类Dev

Spring框架中的对象初始化

来自分类Dev

Kotlin Spring类的方面初始化

来自分类Dev

Spring Web Mvc配置初始化

来自分类Dev

带存储过程的Spring Boot MySQL数据库初始化错误

来自分类Dev

Spring Boot在启动时使用构造函数参数初始化bean

来自分类Dev

使用Spring Boot CLI初始化项目时,如何指定“参数”(例如language = groovy)?

来自分类Dev

使用Spring Boot时未初始化java.lang.IllegalState异常LifecylceProcessor和ApplicationEventMulticaster

来自分类Dev

Spring Boot 2.0.4 + Thymeleaf 3.0.9:无法初始化类HTMLTemplateParser

来自分类Dev

使用Spring Boot时未初始化java.lang.IllegalState异常LifecylceProcessor和ApplicationEventMulticaster

来自分类Dev

在Spring Boot中使用schema.sql初始化一个空表

Related 相关文章

  1. 1

    Spring Boot JPA模式初始化

  2. 2

    Spring Boot 并初始化 sessionFactory

  3. 3

    在Spring Boot启动时初始化表

  4. 4

    在Spring Boot测试之前初始化数据库

  5. 5

    Spring-Boot-jdbcTemplate对象未初始化

  6. 6

    Spring Boot重启时如何防止db初始化

  7. 7

    Spring Boot:无法初始化PostgreSQL数据源

  8. 8

    如何使用spring-boot初始化ActiveMQ的SystemUsage?

  9. 9

    使用RabbitMQ的Spring Boot无法初始化

  10. 10

    Spring Boot 中的上下文初始化问题

  11. 11

    无法从 Spring Boot 初始化 servlet 的 init 方法

  12. 12

    使用Spring Security初始化应用程序时出错:找不到net / sf / ehcache / Ehcache

  13. 13

    Spring的初始化方法

  14. 14

    登录Spring初始化

  15. 15

    Spring如何初始化多个数据源(不带Spring Boot)

  16. 16

    Spring如何初始化多个数据源(不带Spring Boot)

  17. 17

    Spring Context初始化(java)

  18. 18

    Spring中的条件类初始化

  19. 19

    了解Spring Dispatcher Servlet初始化

  20. 20

    Spring框架中的对象初始化

  21. 21

    Kotlin Spring类的方面初始化

  22. 22

    Spring Web Mvc配置初始化

  23. 23

    带存储过程的Spring Boot MySQL数据库初始化错误

  24. 24

    Spring Boot在启动时使用构造函数参数初始化bean

  25. 25

    使用Spring Boot CLI初始化项目时,如何指定“参数”(例如language = groovy)?

  26. 26

    使用Spring Boot时未初始化java.lang.IllegalState异常LifecylceProcessor和ApplicationEventMulticaster

  27. 27

    Spring Boot 2.0.4 + Thymeleaf 3.0.9:无法初始化类HTMLTemplateParser

  28. 28

    使用Spring Boot时未初始化java.lang.IllegalState异常LifecylceProcessor和ApplicationEventMulticaster

  29. 29

    在Spring Boot中使用schema.sql初始化一个空表

热门标签

归档