java的一些简单调用!

来源:互联网 发布:现在淘宝网什么好卖 编辑:程序博客网 时间:2024/06/05 09:57
四、context:component-scan
    <!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
    <context:component-scan base-package="com.haso.bscsserver">
    <!-- 允许定义过滤器将基包下的某些类纳入或排除
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
    </context:component-scan>
    请参,具体的自己还深入研究过
    五、aop注解支持
    <!-- aop注解支持 -->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    六、缓存配置
    <!-- 缓存配置 -->
    <bean id="cacheManager"
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="/WEB-INF/ehcache.xml"/>
    </bean>
    <!-- A facade to the Ehcache cache class -->
    <bean id="cacheProviderFacade"
    class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
    <property name="cacheManager" ref="cacheManager" />
    </bean>
    <?xml version="1.0" encoding="UTF-8"?>
    <ehcache>
    ehcache.xml文件:
    <!--
    name:Cache的唯一标识
    maxElementsInMemory:内存中最大缓存对象数
    maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大
    eternal:Element是否永久有效,一但设置了,timeout将不起作用
    overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中
    timeToIdleSeconds:设置Element在失效前的允许闲置时间。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大
    timeToLiveSeconds:设置Element在失效前允许存活时间。最大时间介于创建时间和失效时间之间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大
    diskPersistent:是否缓存虚拟机重启期数据
    diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒
    diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB.每个Cache都应该有自己的一个缓冲区
    memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)
    -->
    <defaultCache overflowToDisk="true" eternal="true"/>
    <diskStore path="C:/cache" />
    <cache name="zzugxy" overflowToDisk="true" eternal="false"
    timeToIdleSeconds="300" timeToLiveSeconds="600" maxElementsInMemory="1000"
    maxElementsOnDisk="10" diskPersistent="true" diskExpiryThreadIntervalSeconds="300"
    diskSpoolBufferSizeMB="100" memoryStoreEvictionPolicy="LRU" />
    </ehcache>
    ***********************************************
    注解缓存的配置:
    参考(出自):
    关于spring实现ehcache有很多方法,很多都是利用aop来实现,我认为采用注解的方式更灵活,配置也更简洁。下面就是我利用spring-modules-0.9实现的注解缓存。
    配置文件如下:
    [xhtml] view plaincopyprint?
    
    <ehcache:annotations>
    <ehcache:caching id="testCache" cacheName="testCache" />
    <ehcache:flushing id="testFlush" cacheNames="testCache"/>
    </ehcache:annotations>
    </beans>
    这里一定要注意:
    xmlns:ehcache=
    我就在这里花了很长时间,查了很多资料。网上的很多资料说这是spring-moduls的bug.很多朋友在这里总是报找到xsd文件。
    在ehcache.xml中加入
    [xhtml] view plaincopyprint?
    <cache name="testCache" maxElementsInMemory="20000"
    maxElementsOnDisk="1000" eternal="true" overflowToDisk="true"
    memoryStoreEvictionPolicy="LFU" />
    **********************************
    七、
    <!-- Spring、MyBatis的整合,需要在 Spring 应用上下文中定义至少两样东西:一个SqlSessionFactory和至少一个数据映射器类(UserMapper->iocContext.xml)。 -->
    <bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:SqlMapConfig.xml" />
    <property name="dataSource" ref="dataSource" />
    </bean>
0 0