Java配置文件Word文件下载.docx
- 文档编号:21326370
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:9
- 大小:19.70KB
Java配置文件Word文件下载.docx
《Java配置文件Word文件下载.docx》由会员分享,可在线阅读,更多相关《Java配置文件Word文件下载.docx(9页珍藏版)》请在冰豆网上搜索。
--1T=1073741824字节-->
/bean>
引入其他xml文件
<
--引入其它spring-dao.xml-->
importresource="
classpath*:
geiss/resource/spring/spring-dao.xml"
/>
加载初始化***.properties
--加载初始化文件,数据库配置属性的参数设置等-->
beanid="
propertyConfigurer"
class="
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
locations"
list>
value>
geiss/resource/jdbc/jdbc.properties<
/value>
geiss/resource/hibernate/hibernate.properties<
/list>
/property>
数据库配置信息
dataSourceOne"
class="
com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="
close"
driverClass"
com.mysql.jdbc.Driver"
jdbcUrl"
jdbc:
mysql:
//localhost:
3306/chexian?
useUnicode=true&
amp;
characterEncoding=utf8"
user"
root"
password"
123456"
acquireIncrement"
5"
--当连接池中的连接用完时,C3P0一次性创建新连接的数目2-->
initialPoolSize"
10"
--初始化时创建的连接数,必须在minPoolSize和maxPoolSize之间-->
minPoolSize"
maxPoolSize"
20"
--最大空闲时间,超过空闲时间的连接将被丢弃
[需要注意:
mysql默认的连接时长为8小时(28800)
【可在my.ini中添加wait_timeout=30(单位秒)设置连接超时】,这里设置c3p0的超时必须<
28800]
-->
maxIdleTime"
300"
idleConnectionTestPeriod"
60"
--每60秒检查连接池中的空闲连接-->
maxStatements"
--jdbc的标准参数用以控制数据源内加载的PreparedStatement数量,但由于预缓存的Statement属于单个Connection而不是整个连接-->
txManager"
org.springframework.jdbc.datasource.DataSourceTransactionManager"
dataSource"
ref="
</bean>
如果配置信息读取的是***.properties初始化文件
格式<
driver"
${jdbc.driver}"
文件名.键名比如配置session工厂的取值
配置session工厂
--建立session工厂,并将数据源加载进来,同时配置hibernate相关参数信息。
sessionFactory"
org.springframework.orm.hibernate4.LocalSessionFactoryBean"
packagesToScan"
geiss"
hibernateProperties"
<
props>
<
propkey="
hibernate.dialect"
${hibernate.dialect}<
/prop>
hibernate.hbm2ddl.auto"
${hibernate.hbm2ddl.auto}<
hibernate.show_sql"
true<
hibernate.format_sql"
hibernate.query.substitutions"
${hibernate.query.substitutions}<
hibernate.default_batch_fetch_size"
${hibernate.default_batch_fetch_size}<
hibernate.max_fetch_depth"
${hibernate.max_fetch_depth}<
hibernate.generate_statistics"
${hibernate.generate_statistics}<
hibernate.bytecode.use_reflection_optimizer"
${hibernate.bytecode.use_reflection_optimizer}<
hibernate.cache.use_second_level_cache"
${hibernate.cache.use_second_level_cache}<
hibernate.cache.use_query_cache"
${hibernate.cache.use_query_cache}<
hibernate.cache.region.factory_class"
${hibernate.cache.region.factory_class}<
net.sf.ehcache.configurationResourceName"
${net.sf.ehcache.configurationResourceName}<
hibernate.cache.use_structured_entries"
${hibernate.cache.use_structured_entries}<
/props>
数据源的局部事物管理器
--配置JDBC数据源的局部事物管理器-->
org.springframework.orm.hibernate4.HibernateTransactionManager"
hibernate事务相关
--开启注解事务只对当前配置文件有效-->
tx:
annotation-driventransaction-manager="
--配置事物的增强处理bean,指定事物管理器-->
adviceid="
txAdvice"
transaction-manager="
attributes>
methodname="
save*"
propagation="
REQUIRED"
add*"
adds*"
create*"
insert*"
update*"
merge*"
del*"
remove*"
put*"
use*"
execute*"
doWork"
--hibernate4必须配置为开启事务否则getCurrentSession()获取不到-->
get*"
read-only="
count*"
find*"
list*"
*"
--<
/tx:
advice>
Mybatis声明事物
--声明式事务管理-->
aop:
config>
advisorpointcut="
execution(*com.cisetech.service.impl.*ServiceImpl.*(..))"
advice-ref="
myAdvice"
/aop:
rollback-for="
com.cisetech.exception.DaoException"
sqlSessionFactory"
org.mybatis.spring.SqlSessionFactoryBean"
--自动扫描mapper目录,省掉sql-mapper-config.xml里的手工配置-->
typeAliasesPackage"
com.cisetech.mapper"
--显式指定Mapper文件位置-->
mapperLocations"
classpath:
/com/cisetech/mapper/**/*Mapper.xml"
--扫描basePackage下所有以@MyBatisRepository标识的接口-->
beanclass="
org.mybatis.spring.mapper.MapperScannerConfigurer"
basePackage"
annotationClass"
com.cisetech.mapper.MyBatisRepository"
开启AOP监听
--开启AOP监听只对当前配置文件有效-->
--AOP专门处理系统中分布于各模块中的交叉关注点的问题。
aspectj-autoproxyexpose-proxy="
--AOP配置的呀元素-->
configexpose-proxy="
--定义切入点,只对业务逻辑层实施事务即所有的service层下面所有的方法都执行-->
pointcutid="
txPointcut"
execution(*geiss.system..service.impl.*.*(..))"
--指定在txAdvice切入点应用txAdvice事物增强处理-->
advisoradvice-ref="
pointcut-ref="
注册自定义的处理器拦截器
--注册自定义的处理器拦截器-->
mvc:
interceptors>
interceptor>
mappingpath="
/demo/query"
com.cisetech.web.interceptor.MyInterceptor"
/mvc:
配置静态文件
--配置静态文件-->
resourceslocation="
/WEB-INF/resources/css/"
mapping="
/css/**"
/WEB-INF/resources/js/"
/js/**"
/WEB-INF/resources/images/"
jsp页面解析器
--jsp页面解析器,当Controller返回XXX字符串时,先通过拦截器,然后该类就会在/WEB-INF/views/目录下,查找XXX.jsp文件-->
org.springframework.web.servlet.view.InternalResourceViewResolver"
prefix"
/WEB-INF/views/"
suffix"
.jsp"
mapping="
/images/**"
收到相应请求后直接选择相应的视图
--收到相应请求后直接选择相应的视图-->
view-controllerpath="
/"
view-name="
forward:
/index"
WEB.XML
∙初始化过程:
1.在启动Web项目时,容器(比如Tomcat)会读web.xml配置文件中的两个节点<
listener>
和<
contex-param>
。
2.接着容器会创建一个ServletContext(上下文),应用范围内即整个WEB项目都能使用这个上下文。
3.接着容器会将读取到<
context-param>
转化为键值对,并交给ServletContext。
4.容器创建<
/listener>
中的类实例,即创建监听(备注:
listener定义的类可以是自定义的类但必须需要继承ServletContextListener)。
5.在监听的类中会有一个contextInitialized(ServletContextEventevent)初始化方法,在这个方法中可以通过event.getServletContext().getInitParameter("
contextConfigLocation"
)来得到context-param设定的值。
在这个类中还必须有一个contextDestroyed(ServletContextEventevent)销毁方法.用于关闭应用前释放资源,比如说数据库连接的关闭。
6.得到这个context-param的值之后,你就可以做一些操作了.注意,这个时候你的WEB项目还没有完全启动完成.这个动作会比所有的Servlet都要早。
由上面的初始化过程可知容器对于web.xml的加载过程是context-param>
listener
>
fileter
servlet
设置编码
--设置编码-->
filter>
filter-name>
encodingFilter<
/filter-name>
filter-class>
org.springframework.web.filter.CharacterEncodingFilter<
/filter-class>
init-param>
param-name>
encoding<
/param-name>
param-value>
UTF-8<
/param-value>
/init-param>
forceEncoding<
/filter>
filter-mapping>
url-pattern>
/*<
/url-pattern>
/filter-mapping>
创建上下文
contextConfigLocation<
applicationContext-controller.xml,
classpath:
applicationContext-dsone.xml,
applicationContext-job.xml,
applicationContext-ws.xml
/context-param>
创建监听
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
配置SpringMVC的DispatcherServlet
servlet>
servlet-name>
spring-mvc<
/servlet-name>
servlet-class>
org.springframework.web.servlet.DispatcherServlet<
/servlet
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 配置文件