pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<small id='4FLDu'></small><noframes id='4FLDu'>

  • <tfoot id='4FLDu'></tfoot>

      <i id='4FLDu'><tr id='4FLDu'><dt id='4FLDu'><q id='4FLDu'><span id='4FLDu'><b id='4FLDu'><form id='4FLDu'><ins id='4FLDu'></ins><ul id='4FLDu'></ul><sub id='4FLDu'></sub></form><legend id='4FLDu'></legend><bdo id='4FLDu'><pre id='4FLDu'><center id='4FLDu'></center></pre></bdo></b><th id='4FLDu'></th></span></q></dt></tr></i><div class="fzn5zj5" id='4FLDu'><tfoot id='4FLDu'></tfoot><dl id='4FLDu'><fieldset id='4FLDu'></fieldset></dl></div>
        <bdo id='4FLDu'></bdo><ul id='4FLDu'></ul>

      1. <legend id='4FLDu'><style id='4FLDu'><dir id='4FLDu'><q id='4FLDu'></q></dir></style></legend>

        Spring MVC:&lt;context:component-scan&gt; 之間的區別

        Spring MVC: difference between lt;context:component-scangt; and lt;annotation-driven /gt; tags?(Spring MVC:lt;context:component-scangt; 之間的區別和lt;注釋驅動/gt;標簽?)

        1. <i id='mlUXM'><tr id='mlUXM'><dt id='mlUXM'><q id='mlUXM'><span id='mlUXM'><b id='mlUXM'><form id='mlUXM'><ins id='mlUXM'></ins><ul id='mlUXM'></ul><sub id='mlUXM'></sub></form><legend id='mlUXM'></legend><bdo id='mlUXM'><pre id='mlUXM'><center id='mlUXM'></center></pre></bdo></b><th id='mlUXM'></th></span></q></dt></tr></i><div class="nvlzjfj" id='mlUXM'><tfoot id='mlUXM'></tfoot><dl id='mlUXM'><fieldset id='mlUXM'></fieldset></dl></div>

        2. <small id='mlUXM'></small><noframes id='mlUXM'>

          <tfoot id='mlUXM'></tfoot><legend id='mlUXM'><style id='mlUXM'><dir id='mlUXM'><q id='mlUXM'></q></dir></style></legend>
            <tbody id='mlUXM'></tbody>

                <bdo id='mlUXM'></bdo><ul id='mlUXM'></ul>

                • 本文介紹了Spring MVC:&lt;context:component-scan&gt; 之間的區別和&lt;注釋驅動/&gt;標簽?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  前幾天開始研究這個Spring Hello World教程:http://viralpatel.net/blogs/spring-3-mvc-create-hello-world-application-spring-3-mvc/

                  Some days ago I began to study this Spring Hello World Tutorial: http://viralpatel.net/blogs/spring-3-mvc-create-hello-world-application-spring-3-mvc/

                  在本教程中,Spring DispatcherServlet 是使用 spring-servlet.xml 文件配置的,這個:

                  In this tutorial Spring DispatcherServlet is configured using the spring-servlet.xml file, this one:

                  <?xml version="1.0" encoding="UTF-8"?>
                   <beans xmlns="http://www.springframework.org/schema/beans"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xmlns:p="http://www.springframework.org/schema/p"
                      xmlns:context="http://www.springframework.org/schema/context"
                  
                  xsi:schemaLocation="
                      http://www.springframework.org/schema/beans 
                      http://www.springframework.org/schema/beans/spring-beans.xsd
                      http://www.springframework.org/schema/context 
                      http://www.springframework.org/schema/context/spring-context.xsd">
                  
                  <context:component-scan base-package="net.viralpatel.spring3.controller" />
                  
                  <bean id="viewResolver"
                      class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                      <property name="viewClass"
                          value="org.springframework.web.servlet.view.JstlView" />
                      <property name="prefix" value="/WEB-INF/jsp/" />
                      <property name="suffix" value=".jsp" />
                  </bean>
                  

                  在這個文件中,我使用 context:component-scan 標簽來表示 Spring 必須掃描我的文件以搜索注解,例如,當控制器類發現一個方法被注解時通過 @RequestMapping("/hello") 注釋知道該方法處理向以/hello"結尾的 URL 的 HTTP 請求.這很簡單……

                  In this file I am using the context:component-scan tag to say that Spring have to scan my file searching the annotation, so for example, when the controller class finds that a method is annotated by @RequestMapping("/hello") annotation knows that this method handles the HTTP Request toward the URL ending with "/hello". This is simple...

                  現在我的疑問與我可以在 STSEclipse 中自動構建的 Spring MVC 模板項目有關.

                  Now my doubt is related to the Spring MVC template project that I could automatically build in STSEclipse.

                  當我在 STS 中創建一個新的 Spring MVC 項目時,我的 DispatcherServlet 是由一個名為 servlet-context.xml 的文件配置的,該文件包含一些類似于上一個示例文件.

                  When I create a new Spring MVC project in STS I have that my DispatcherServlet is configured by a file named servlet-context.xml that contains some configuration similar to the previous example file.

                  在這個文件中,我還有組件掃描標簽:

                  In this file, I still have the component scan tag:

                  <context:component-scan base-package="com.mycompany.maventestwebapp" />
                  

                  但我還有另一個標簽(看起來有類似的任務),這個:

                  but I have also another tag (that look like have similar task), this one:

                  <annotation-driven />
                  

                  這兩個標簽有什么區別?
                  另一個奇怪"的事情是前面的示例(不使用注釋驅動標簽)與 STS 使用 Spring MVC 模板項目創建的項目非常相似,但是如果我從其配置中刪除注釋驅動標簽文件項目不運行并給我以下錯誤:HTTP Status 404 -

                  What is the difference between these two tags?
                  An other "strange" thing is that the previous example (that don't use the annotation-driven tag) is very similar to the project create by STS using the Spring MVC Template project but if I delete the annotation-driven tag from its configuration file the project don't run and give me the following error: HTTP Status 404 -

                  在堆棧跟蹤中我有:

                  警告:org.springframework.web.servlet.PageNotFound - 在名為appServlet"的 DispatcherServlet 中找不到具有 URI [/maventestwebapp/] 的 HTTP 請求的映射

                  但是為什么呢?前面的例子在沒有注釋驅動標簽的情況下運行良好,這個控制器類非常相似.實際上,只有一種方法可以處理對/"路徑的 HTTP 請求

                  But why? The previous example works well without annotation-driven tag, and this controller class is very similar. In fact, there is only one method that handles HTTP request toward "/" path

                  這是我的控制器類的代碼:

                  This is the code of my controller class:

                  package com.mycompany.maventestwebapp;
                  
                  import java.text.DateFormat;
                  import java.util.Date;
                  import java.util.Locale;
                  
                  import org.slf4j.Logger;
                  import org.slf4j.LoggerFactory;
                  import org.springframework.stereotype.Controller;
                  import org.springframework.ui.Model;
                  import org.springframework.web.bind.annotation.RequestMapping;
                  import org.springframework.web.bind.annotation.RequestMethod;
                  
                  /**
                   * Handles requests for the application home page.
                  */
                  @Controller
                  public class HomeController {
                  
                  private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
                  
                  /**
                   * Simply selects the home view to render by returning its name.
                   */
                  @RequestMapping(value = "/", method = RequestMethod.GET)
                  public String home(Locale locale, Model model) {
                      logger.info("Welcome home! The client locale is {}.", locale);
                  
                      Date date = new Date();
                      DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
                  
                      String formattedDate = dateFormat.format(date);
                  
                      model.addAttribute("serverTime", formattedDate );
                  
                      return "home";
                  }
                  

                  有人可以幫我理解這件事嗎?

                  Can someone help me to understand this thing?

                  非常感謝!

                  推薦答案

                  <mvc:annotation-driven/> 表示可以定義spring beans依賴,而不必實際指定一堆XML 中的元素或實現接口或擴展基類.例如 @Repository 告訴 spring 一個類是一個 Dao,而不必擴展 JpaDaoSupport 或 DaoSupport 的一些其他子類.類似地,@Controller 告訴 spring,指定的類包含將處理 Http 請求的方法,而無需實現 Controller 接口或擴展實現控制器的子類.

                  <mvc:annotation-driven /> means that you can define spring beans dependencies without actually having to specify a bunch of elements in XML or implement an interface or extend a base class. For example @Repository to tell spring that a class is a Dao without having to extend JpaDaoSupport or some other subclass of DaoSupport. Similarly @Controller tells spring that the class specified contains methods that will handle Http requests without you having to implement the Controller interface or extend a subclass that implements the controller.

                  當 spring 啟動時,它會讀取其 XML 配置文件并在其中查找 <bean 元素,如果它看到類似 <bean class="com.example.Foo"/> 并且 Foo 被標記為 @Controller 它知道該類是控制器并將其視為控制器.默認情況下,Spring 假定它應該管理的所有類都明確定義在 beans.XML 文件中.

                  When spring starts up it reads its XML configuration file and looks for <bean elements within it if it sees something like <bean class="com.example.Foo" /> and Foo was marked up with @Controller it knows that the class is a controller and treats it as such. By default, Spring assumes that all the classes it should manage are explicitly defined in the beans.XML file.

                  使用 <context:component-scan base-package="com.mycompany.maventestwebapp"/> 進行組件掃描告訴 spring 它應該在類路徑中搜索 com 下的所有類.mycompany.maventestweapp 并查看每個類以查看它是否具有 @Controller@Repository@Service@Component 如果是,那么 Spring 將向 bean 工廠注冊該類,就像您在 XML 配置文件中鍵入 <bean class="..."/>.

                  Component scanning with <context:component-scan base-package="com.mycompany.maventestwebapp" /> is telling spring that it should search the classpath for all the classes under com.mycompany.maventestweapp and look at each class to see if it has a @Controller, or @Repository, or @Service, or @Component and if it does then Spring will register the class with the bean factory as if you had typed <bean class="..." /> in the XML configuration files.

                  在一個典型的 Spring MVC 應用程序中,你會發現有兩個 Spring 配置文件,一個配置應用程序上下文的文件通常以 Spring 上下文偵聽器啟動.

                  In a typical spring MVC app you will find that there are two spring configuration files, a file that configures the application context usually started with the Spring context listener.

                  <listener>
                      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                  </listener>
                  

                  Spring MVC 配置文件通常以 Spring 調度程序 servlet 啟動.例如.

                  And a Spring MVC configuration file usually started with the Spring dispatcher servlet. For example.

                  <servlet>
                          <servlet-name>main</servlet-name>
                          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                          <load-on-startup>1</load-on-startup>
                      </servlet>
                      <servlet-mapping>
                          <servlet-name>main</servlet-name>
                          <url-pattern>/</url-pattern>
                      </servlet-mapping>
                  

                  Spring 支持分層 bean 工廠,因此在 Spring MVC 的情況下,調度程序 servlet 上下文是主應用程序上下文的子級.如果向 servlet 上下文詢問名為abc"的 bean,它將首先在 servlet 上下文中查找,如果在其中找不到它,它將在父上下文中查找,即應用程序上下文.

                  Spring has support for hierarchical bean factories, so in the case of the Spring MVC, the dispatcher servlet context is a child of the main application context. If the servlet context was asked for a bean called "abc" it will look in the servlet context first, if it does not find it there it will look in the parent context, which is the application context.

                  數據源、JPA 配置、業務服務等通用 bean 是在應用程序上下文中定義的,而 MVC 特定配置不是與 servlet 關聯的配置文件.

                  Common beans such as data sources, JPA configuration, business services are defined in the application context while MVC specific configuration goes not the configuration file associated with the servlet.

                  希望這會有所幫助.

                  這篇關于Spring MVC:&lt;context:component-scan&gt; 之間的區別和&lt;注釋驅動/&gt;標簽?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                  Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                  Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                  What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                  Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                  Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)

                        <tbody id='psQmf'></tbody>

                      • <bdo id='psQmf'></bdo><ul id='psQmf'></ul>
                        <tfoot id='psQmf'></tfoot>
                      • <legend id='psQmf'><style id='psQmf'><dir id='psQmf'><q id='psQmf'></q></dir></style></legend>

                          <i id='psQmf'><tr id='psQmf'><dt id='psQmf'><q id='psQmf'><span id='psQmf'><b id='psQmf'><form id='psQmf'><ins id='psQmf'></ins><ul id='psQmf'></ul><sub id='psQmf'></sub></form><legend id='psQmf'></legend><bdo id='psQmf'><pre id='psQmf'><center id='psQmf'></center></pre></bdo></b><th id='psQmf'></th></span></q></dt></tr></i><div class="hdzrfp5" id='psQmf'><tfoot id='psQmf'></tfoot><dl id='psQmf'><fieldset id='psQmf'></fieldset></dl></div>

                            <small id='psQmf'></small><noframes id='psQmf'>

                            主站蜘蛛池模板: 超声波_清洗机_超声波清洗机专业生产厂家-深圳市好顺超声设备有限公司 | 综合管廊模具_生态,阶梯护坡模具_检查井模具制造-致宏模具厂家 | 贴片电容-贴片电阻-二三极管-国巨|三星|风华贴片电容代理商-深圳伟哲电子 | 物流公司电话|附近物流公司电话上门取货| 精密模具加工制造 - 富东懿 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 通用磨耗试验机-QUV耐候试验机|久宏实业百科 | 合肥地磅_合肥数控切割机_安徽地磅厂家_合肥世佳电工设备有限公司 | 昆明网络公司|云南网络公司|昆明网站建设公司|昆明网页设计|云南网站制作|新媒体运营公司|APP开发|小程序研发|尽在昆明奥远科技有限公司 | 即用型透析袋,透析袋夹子,药敏纸片,L型涂布棒-上海桥星贸易有限公司 | Jaeaiot捷易科技-英伟达AI显卡模组/GPU整机服务器供应商 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 艾默生变频器,艾默生ct,变频器,ct驱动器,广州艾默生变频器,供水专用变频器,风机变频器,电梯变频器,艾默生变频器代理-广州市盟雄贸易有限公司官方网站-艾默生变频器应用解决方案服务商 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | 浙江建筑资质代办_二级房建_市政_电力_安许_劳务资质办理公司 | 隆众资讯-首页_大宗商品资讯_价格走势_市场行情 | 皮带输送机-大倾角皮带输送机-皮带输送机厂家-河南坤威机械 | 橡胶接头_橡胶软接头_可曲挠橡胶接头-巩义市创伟机械制造有限公司 | 浙江筋膜枪-按摩仪厂家-制造商-肩颈按摩仪哪家好-温州市合喜电子科技有限公司 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 杭州中央空调维修_冷却塔/新风机柜/热水器/锅炉除垢清洗_除垢剂_风机盘管_冷凝器清洗-杭州亿诺能源有限公司 | 北京普辉律师事务所官网_北京律师24小时免费咨询|法律咨询 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 电缆桥架生产厂家_槽式/梯式_热镀锌线槽_广东东莞雷正电气 | 道康宁消泡剂-瓦克-大川进口消泡剂供应商 | 东莞动力锂电池保护板_BMS智能软件保护板_锂电池主动均衡保护板-东莞市倡芯电子科技有限公司 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 全自动实验室洗瓶机,移液管|培养皿|进样瓶清洗机,清洗剂-广州摩特伟希尔机械设备有限责任公司 | 电磁辐射仪-电磁辐射检测仪-pm2.5检测仪-多功能射线检测仪-上海何亦仪器仪表有限公司 | 压力控制器,差压控制器,温度控制器,防爆压力控制器,防爆温度控制器,防爆差压控制器-常州天利智能控制股份有限公司 | 压装机-卧式轴承轮轴数控伺服压装机厂家[铭泽机械] | 涂层测厚仪_光泽度仪_uv能量计_紫外辐照计_太阳膜测试仪_透光率仪-林上科技 | 优宝-汽车润滑脂-轴承润滑脂-高温齿轮润滑油脂厂家 | 洁净实验室工程-成都手术室净化-无尘车间装修-四川华锐净化公司-洁净室专业厂家 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 |