Java配置文件讲解.docx
- 文档编号:6547718
- 上传时间:2023-05-10
- 格式:DOCX
- 页数:12
- 大小:19.65KB
Java配置文件讲解.docx
《Java配置文件讲解.docx》由会员分享,可在线阅读,更多相关《Java配置文件讲解.docx(12页珍藏版)》请在冰点文库上搜索。
Java配置文件讲解
扫描注解
--自动扫描指定路径下的包,将带有@Component、@Respository、@Service、@Controller等标签的类自动注册到spring容器中-->
component-scanbase-package="geiss.*"> --context: include-filter意思是扫描不在geisss包下面的类或其它。 --> include-filtertype="annotation"expression="org.springframework.stereotype.Controller"/> component-scan> 上传文件 --上传文件时使用--> class="mons.CommonsMultipartResolver"> --1T=1073741824字节--> 引入其他xml文件 --引入其它spring-dao.xml--> geiss/resource/spring/spring-dao.xml"/> 加载初始化***.properties --加载初始化文件,数据库配置属性的参数设置等--> geiss/resource/jdbc/jdbc.properties geiss/resource/hibernate/hibernate.properties 数据库配置信息 mysql: //localhost: 3306/chexian? useUnicode=true&characterEncoding=utf8"> --当连接池中的连接用完时,C3P0一次性创建新连接的数目2--> --初始化时创建的连接数,必须在minPoolSize和maxPoolSize之间--> --最大空闲时间,超过空闲时间的连接将被丢弃 [需要注意: mysql默认的连接时长为8小时(28800)【可在my.ini中添加wait_timeout=30(单位秒)设置连接超时】,这里设置c3p0的超时必须<28800] --> --每60秒检查连接池中的空闲连接--> --jdbc的标准参数用以控制数据源内加载的PreparedStatement数量,但由于预缓存的Statement属于单个Connection而不是整个连接--> </bean> 如果配置信息读取的是***.properties初始化文件 格式 配置session工厂 --建立session工厂,并将数据源加载进来,同时配置hibernate相关参数信息。 --> 数据源的局部事物管理器 --配置JDBC数据源的局部事物管理器--> hibernate事务相关 --开启注解事务只对当前配置文件有效--> annotation-driventransaction-manager="txManager"/> --配置事物的增强处理bean,指定事物管理器--> adviceid="txAdvice"transaction-manager="txManager"> attributes> methodname="save*"propagation="REQUIRED"/> methodname="add*"propagation="REQUIRED"/> methodname="adds*"propagation="REQUIRED"/> methodname="create*"propagation="REQUIRED"/> methodname="insert*"propagation="REQUIRED"/> methodname="update*"propagation="REQUIRED"/> methodname="merge*"propagation="REQUIRED"/> methodname="del*"propagation="REQUIRED"/> methodname="remove*"propagation="REQUIRED"/> methodname="put*"propagation="REQUIRED"/> methodname="use*"propagation="REQUIRED"/> methodname="execute*"propagation="REQUIRED"/> methodname="doWork"propagation="REQUIRED"/> --hibernate4必须配置为开启事务否则getCurrentSession()获取不到--> methodname="get*"propagation="REQUIRED"read-only="true"/> methodname="count*"propagation="REQUIRED"read-only="true"/> methodname="find*"propagation="REQUIRED"read-only="true"/> methodname="list*"propagation="REQUIRED"read-only="true"/> methodname="*"/> -- methodname="*"read-only="true"/>--> attributes> advice> Mybatis声明事物 --声明式事务管理--> config> advisorpointcut="execution(*com.cisetech.service.impl.*ServiceImpl.*(..))"advice-ref="myAdvice"/> config> adviceid="myAdvice"transaction-manager="txManager"> attributes> methodname="add*"propagation="REQUIRED"/> methodname="update*"propagation="REQUIRED"/> methodname="*"read-only="true"rollback-for="com.cisetech.exception.DaoException"/> attributes> advice> --自动扫描mapper目录,省掉sql-mapper-config.xml里的手工配置--> --显式指定Mapper文件位置--> /com/cisetech/mapper/**/*Mapper.xml"/> --扫描basePackage下所有以@MyBatisRepository标识的接口--> 开启AOP监听 --开启AOP监听只对当前配置文件有效--> --AOP专门处理系统中分布于各模块中的交叉关注点的问题。 --> aspectj-autoproxyexpose-proxy="true"/> --AOP配置的呀元素--> configexpose-proxy="true"> --定义切入点,只对业务逻辑层实施事务即所有的service层下面所有的方法都执行--> pointcutid="txPointcut"expression="execution(*geiss.system..service.impl.*.*(..))"/> --指定在txAdvice切入点应用txAdvice事物增强处理--> advisoradvice-ref="txAdvice"pointcut-ref="txPointcut"/> config> 注册自定义的处理器拦截器 --注册自定义的处理器拦截器--> interceptors> interceptor> mappingpath="/demo/query"/> interceptor> interceptors> 配置静态文件 --配置静态文件--> resourceslocation="/WEB-INF/resources/css/"mapping="/css/**"/> resourceslocation="/WEB-INF/resources/js/"mapping="/js/**"/> resourceslocation="/WEB-INF/resources/images/" jsp页面解析器 --jsp页面解析器,当Controller返回XXX字符串时,先通过拦截器,然后该类就会在/WEB-INF/views/目录下,查找XXX.jsp文件--> mapping="/images/**"/> 收到相应请求后直接选择相应的视图 --收到相应请求后直接选择相应的视图--> view-controllerpath="/"view-name="forward: /index"/> WEB.XML ∙初始化过程: 1.在启动Web项目时,容器(比如Tomcat)会读web.xml配置文件中的两个节点 2.接着容器会创建一个ServletContext(上下文),应用范围内即整个WEB项目都能使用这个上下文。 3.接着容器会将读取到 4.容器创建 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 设置编码 --设置编码--> 创建上下文 applicationContext-controller.xml, classpath: applicationContext-dsone.xml, classpath: applicationContext-job.xml, classpath: applicationContext-ws.xml 创建监听 配置SpringMVC的DispatcherServlet
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 配置文件 讲解