我想在本地託管的Spring應用程序中使用favicon。按照favicon.ico not displaying in spring mvc 3.2.2 per Tomcat 7.0?,我在web.xml中添加在Spring MVC應用程序中使用favicon問題
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
:
<display-name>Coaching</display-name>
<servlet>
<servlet-name>Coaching</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
添加
<mvc:default-servlet-handler />
config.xml中
是給我的錯誤,同時運行的應用程序或應用程序實際上沒有運行。我的applicationContext.xml是:
<context:component-scan base-package="com.coaching.controller" />
<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views
directory -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
我的favicon.ico是在Web應用程序的根目錄(又名一起來從WEB-INF)目錄(Add favicon from Spring MVC)。但它沒有出現在網址欄中。我將它渲染爲
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
在jsp頁面的頭部。我甚至試過https://stackoverflow.com/a/17039121/2116229,但應用程序沒有再次運行。
我已經試過了圖標,但沒有任何結果的幾個地點。它一定是需要一些彈簧mvc配置。有人能告訴我我錯過了什麼嗎?
我希望圖標也出現在本地主機了。
對你的配置的評論與你的問題無關。您正在加載您的配置兩次,基本上覆制所有的豆。 DispatcherServlet和ContextLoaderListener都加載了相同的XML文件(applicationContext.xml)。 –
感謝您指出...... :)出於好奇,這會對我的應用程序產生長期影響嗎?像內存問題或任何其他影響... –
當你正在複製你的豆你基本上重複你的應用程序的內存使用情況。當你的配置變得越來越複雜時,你也可以體驗到更多「有趣」的問題(至少這是我解決問題的經驗:))。 –