2016-08-09 4 views
0

Ich entwickle ein Projekt mit Spring Boot und Ehcache.Spring Boot initialisiert Ehcache nicht

Wenn ich eine Methode dieses Projekts mit Junit ausführen, sehe ich, dass Ehcache vollständig initialisiert ist.

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'. 

Aber wenn ich Frühlings-Boot für das gleiche Projekt verwenden, sehe ich nicht die, die Ehcahe vollständig initialisiert.

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[email protected]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[email protected]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  : 

Wenn ich Frühling Stiefel, ich sehe keine Linien mit Statistik: LOCAL_OFFHEAP_SIZE_BYTES Statistik: LOCAL_DISK_SIZE Statistik: LOCAL_DISK_SIZE_BYTES

Außerdem sehe ich nicht, Weg der Plattenspeicher meines Cache , wie im ersten Beispiel: DiskStoreConfiguration - Plattenspeicherpfad: C: \ TEMP \

Die Protokollierungseinstellungen sind für jede Ausführung gleich.

Warum passiert das?

Frühjahr Boot Module:

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> 

Antwort

3

Protokolleinstellungen sind die gleichen für jede Ausführung

Die anderen Format der Ausgabe sagt mir, dass das nicht ist Das ist der Fall.

standardmäßig Unit-Tests werden DEBUG als Root-Protokollebene verwenden, wo, wie, wenn Sie Ihre Frühlings-Boot-Anwendung der Standard-Protokollebene starten ist INFO zuzüglich Anpassung Sie in application.properties gemacht haben. Zum Beispiel können Sie die DEBUG-Nachrichten von org.springframework.web aufgrund Ihrer Konfiguration sehen.

Wenn Sie DEBUG-Nachrichten von ehcache sehen möchten, wenn Sie Ihre Anwendung starten, aktualisieren Sie Ihre application.properties:

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