xml怎么配置文件|如何调试xml配置文件

⑴ spring boot框架的web.xml文件怎么配置

Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xml。当需要载入多个spring相关的配置文件时,首先加载ContextLoaderListener类,再指定context-param中指定多个spring配置文件,使用逗号分别隔开各个文件。为了使用方便可以将配置文件进行MVC式的分解,配置控制器Bean的配置文件放置在一个xml文件中,server的Bean放在service.xml文件中。

⑵ 如何调试xml配置文件

在Eclipse下编辑XML文件时可以像java文件一样进行格式化。不过,默认的格式化设置效果不太理想,尤其是标签属性较多时。通过以下设置可以达到一个相对理想的效果:Window -> Preferences -> XML ->XML Files -> Editor :1.1设置每行宽度Line width 设定为80到100个字符。1.2标签的每个属性都单独一行显示:选中Split multiple attributes each on a new line1.3 标签结束符不单独占用一行:不选中Align final bracket in multi-line element tags1.4去掉所有空行:选中Clear all blank lines1.5 在标签结束符前添加空格:选中Insert whitespace before closing empty end-tags1.6缩进使用空格代替tab:选中Indent using spaces1.7 设定缩进宽度Indentation size 设定为4,即缩进4个空格。

⑶ web.xml中相关配置

在web.xml中通过contextConfigLocation配置spring,contextConfigLocation参数定义了要装入的 Spring 配置文件

部署applicationContext.xml文件 如果不写任何参数配置,默认的是在/WEB-INF/applicationContext.xml 如果指定了要加载的文件,则会去歼咐加载相应的xml,而不会去加氏慧纯载/WEB-INF/下的applicationContext.xml。如果没有指定的话,碧皮默认会去/WEB-INF/下加载applicationContext.xml。 如果想要自定义文件名,需要在web.xml中加入contextConfigLocation这个context参数 springmvc的默认配置文件是放在WEB-INF下的,并且要命名为 -servlet.xml, 为servlet—name,即下文中的”Springmvc”

web.xml文件中webAppRootKey属性是web项目的绝对路径,默认值是webApp.root,可以通过System.getProperty(“webApp.root”)来获取属性值或者在配置文件中通过${webApp.root}获得。

Spring通过 org.springframework.web.util.WebAppRootListener 这个监听器来注入项目路径,因此部署在同一个web容器中的项目,要配置不同的param-value(比如”项目名.root”),不然会造成冲突。但是如果在web.xml中已经配置了org.springframework.web.util.Log4jConfigListener这个监听器,则不需要配置WebAppRootListener了。因为Log4jConfigListener已经包含了WebAppRootListener的功能。WebAppRootListener要在ApplicationContext的ContextLoaderListener之前,否则ApplicationContext的bean注入根目录值时会发生无法注入异常。

“webapp.root”这个字符串可以随便写任何字符串。如果不配置默认值是”webapp.root”。

可以用System.getProperty(“webapp.root”)来动态获项目的运行路径。 一般返回结果例如:/usr/local/tomcat6/webapps/项目名

定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里。 然后log4j的配置文件里就可以用${webName.root }来表示Web目录的绝对路径,把log文件存放于webapp中。 此参数用于后面的“Log4jConfigListener”–>

⑷ ssh框架的xml文件怎么配置

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!– 配置spring的监听器 –> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</顷慎param-value> </context-param> <!– 开启监听 –> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!– 配置OpenSessionInViewFilter,必须在struts2监听之前 –> <!– <filter> <filter-name>lazyLoadingFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name>lazyLoadingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> –> <!– 设置监听加载上下文 –> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</早困filter-name> <url-pattern>/陆乎念*</url-pattern> <!–注意:千万不能写成:*.action ,如果需要:*.action应该配置在struts.xml中–> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>

⑸ “spring boot”框架的“web.xml”文件怎么配置

首先我们先配置welcomefile-list

我们先声明一个类继承WebMvcConfigurerAdapter重写如下方法即可

注解不能忘

@[email protected]@ComponentScan(basePackages =

@Overridepublic void addViewControllers(ViewControllerRegistry registry){

registry.addViewController("/").setViewName("forward:/login.html");}配置controller类返回至指定目录,需要重写如下方法

@Beanpublic ViewResolver viewResolver() {

InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/view/"); resolver.setSuffix(".jsp"); resolver.(true); return resolver;}

我们把另一个类用于配置监听事件编码

Configurationpublic class WebInitializer extends {

getRootConfigClasses 用于配置最先执行的一些配置文件,如RootConfig.java 比如自定义的filter

getServletConfigClasses 这个文件是用于配置welcomefilelist 前置目录+后缀 error-page等

⑹ hibernate.cfg.xml怎么添加xml配置文件

Hibernate默认的配置文件路裤档没径是/hibernate.cfg.xml,如果你不想使用默认路径。比如你把配置文件都放到conf目录下面。那如何修改Hibernate的config路径呢。其实也很简单。看我蠢漏写的HibernateUti类。(Hibernate hibernate.cfg.xml 配置路径) (Hibernate hibernate.cfg.xml 配置路径)(Hibernate hibernate.cfg.xml 配置路径)(Hibernate hibernate.cfg.xml 配置路径)(Hibernate hibernate.cfg.xml 配置路径)(Hibernate hibernate.cfg.xml 配置路径)我们只要把sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();改为:sessionFactory = new AnnotationConfiguration().configure(new File("../conf/hibernate.cfg.xml")).buildSessionFactory();就可也了。../conf/hibernate.cfg.xml就是你的路胡纳径。

⑺ 如何用基于xml配置的方式配置spring

对于大多数的应用,从表现层的action,到持久层的DataSource,都被Spring 作为bean 管理。如果这些bean 被配置在同一个文件中,阅读及维护该配置文件将是一件非常有挑战的事情。因此, Spring 建议:将一个大的配置文件分解成多个小的配置文件,使每个配置文件仅仅唤袭团管理功能近似于bean; 这样不仅可以分散配置文件,降低修改配置文件的风险,而且更符合"分而治之"的软件工程原理。多个配置文件最终需要汇总, ApplicationContext提供如下方式来汇总多个配置文件:.使用App1icationContext 加载多个配置文件。• Web 应用启动时加载多个配置文件。• XML 配置文件中导入其他配置。1 ApplicationContext 加载多个配置文件 ApplicatonContext 的常用实现类有如下两个:• ClassPathXm1 ApplicationContext 。• 。这两个类都可以用来加载多个配置文件,它们的构造器都可以接收一个数组,并在该数组中存放多个配置文件。 可采用如下代码加载多个配置文件:/I创建配置文件数组/I假设有3 个配置文件: a.xml , b.xml , c.xmlStr工ng[) configLocations = {"a.xml" , "b.xml" , "c.xml"}以配置文件数组为参数,创建ApplicationContextApplicationContext ctx = new (configLocations);与采用创建ApplicationContext的方式相似,区别仅在于二者搜索配置文件的路径不同:通过CLASSPATH路径搜索配置文件:而则在当前路径搜索配置文件。2 Web 应用启动时加载多个配置文件 参看5.12.3 节所述,通过ContextLoaderListener 也可加载多个配置文件,可利用337轻量级J2EE 企业应用实战一一-Struts+Spring+Hibernate 整和橘合开发<context-pararn>元素来指定多个配置文件位置,其配置如下:<l– 确定配置文件的位置一〉<context-param><param-name>contextConfigLocation</param-name><1– 此处可以列出多个Spring 的XML 配置文件><param-value>/WEB-INF/Context.xml IWEB-INF/applicationContext.xml<1param-value><context-param>3 XML 配置文件中导人其他配置文件 配置文件本身和其子元素import. 可用于导入其他配置文件。具体的配置禅余示例如下:<?xml version="1.0" encod工口g="gb2312"?><!一指定Spring 配置文件的dtd><!DOCTYPE beans PUBLIC "-IISPR工NGIIDTD BEANIIEN"''htt p:/ /ww w.springframe work.o rg/dtd/spring-beans.dtd''><!– Spring 配置文件的根元素-><beans><!一导入第→份配置文件: serv工ces.xml一〉<import resource="serv工ces.xml"l><!– 导入第二份配置文件: resources/messageSource.xml 一〉<import resource="resources/messageSource.xml"l><!– 导入第二份配置文件: resourcesl themeSource.xml –><import resource="/resources/themeSource.xml"l><!– 下面定义该文件垦的其他bean…〉<bean id="beanl" class=". .."1><bean id="bea口2" class="…"I></beans>


赞 (0)