導航:首頁 > 文件管理 > xml怎麼配置文件

xml怎麼配置文件

發布時間:2023-05-30 19:24:07

⑴ 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 line
1.3 標簽結束符不單獨佔用一行:
不選中Align final bracket in multi-line element tags
1.4去掉所有空行:
選中Clear all blank lines
1.5 在標簽結束符前添加空格:
選中Insert whitespace before closing empty end-tags
1.6縮進使用空格代替tab:
選中Indent using spaces
1.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重寫如下方法即可

註解不能忘

@Configuration@EnableWebMvc@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.xml
Str工ng[) configLocations = {"a.xml" , "b.xml" , "c.xml"}
以配置文件數組為參數,創建ApplicationContext
ApplicationContext 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<1
param-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>

閱讀全文

與xml怎麼配置文件相關的資料

熱點內容
ppt的文件名後綴 瀏覽:902
ug編程軟體下載到哪個盤 瀏覽:359
炫酷字體APP下載的文件在哪裡 瀏覽:668
廊坊哪裡有少兒編程機構 瀏覽:312
cad新文件能找回來嗎 瀏覽:951
導出手機qq文件到u盤 瀏覽:456
電腦如何打開ppt文件怎麼打開方式 瀏覽:782
魅族鎖定區文件夾 瀏覽:357
刻字cnc怎麼編程 瀏覽:182
學校的網路拓撲結構圖 瀏覽:784
收集100個pdf文件里關鍵詞 瀏覽:594
蘋果關閉4g網路設置 瀏覽:289
如何監測資料庫 瀏覽:967
拷貝過來的pdf文件 瀏覽:751
抖音小店的訪客數據怎麼看 瀏覽:670
怎麼把c語言編程的字元向下移動 瀏覽:786
sql刪除文件組代碼 瀏覽:978
安卓post請求多重json 瀏覽:776
微信消除數據怎麼恢復 瀏覽:918
小米刷機顯示系統找不到指定文件 瀏覽:528

友情鏈接