我很难让我的Spring 3.0应用程序将favicon.ico类型文件识别为资源.我在我的spring-context.xml文件中定义了我的资源目录,如下所示:
<mvc:resources mapping="/ui/**" location="/ui/" />
Run Code Online (Sandbox Code Playgroud)
此目录结构如下所示:
/ui
/images
/styles
/scripts
...
Run Code Online (Sandbox Code Playgroud)
Spring可以很好地托管我的图像,脚本和样式.但是,尝试检索*.icoimages目录中的任何文件时出现404错误.所有PNG,GIF和JPG图像在同一目录中都可以正常工作.我尝试更具体地说明要托管哪些目录,甚至指定.ico文件作为文件中的资源context.xml,仍然得到相同的结果:
<mvc:resources mapping="/ui/images/*.ico" location="/ui/images" />
Run Code Online (Sandbox Code Playgroud)
我也尝试将servlet映射添加到默认的servlet.当我在网上进行研究时,这似乎对某些人有用,但对我来说并没有证明是成功的.
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.ico</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
编辑:我还将favicon.ico文件添加到Web应用程序的根路径.如果我使用一个png文件作为favicon,它适用于每个浏览器,但IE.如果可能的话,我想为所有浏览器解决这个问题.在这一点上任何帮助将不胜感激.
EDIT2:我已经在XHTML文档中有一个链接标记:
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/ui/images/favicon.ico" />
Run Code Online (Sandbox Code Playgroud) 首先,我要说我是Go语言的新手,因此在与其他库一起使用时,我正在寻找模拟技术。我很清楚接口和依赖注入是使代码可测试和可模拟的最佳方法。
在使用第三方客户端库(Google云存储)时,尝试模拟其客户端的实现时遇到了问题。主要问题是客户端库中的类型未使用接口实现。我可以生成模仿客户端实现的接口。但是,某些函数的返回值将返回指向基础结构类型的指针,由于私有属性,这些指针很难或无法模拟。这是我要解决的问题的样本:
package third_party
type UnderlyingType struct {
secret string
}
type ThirdPartyClient struct {}
func (f *ThirdPartyClient) SomeFunction() *UnderlyingType {
return &UnderlyingType{
secret: "I can't mock this, it's a secret to the package"
}
}
Run Code Online (Sandbox Code Playgroud)
这是带注释的示例,其中包含我要解决的问题。
package mock
// Create interface that matches third party client structure
type MyClientInterface interface {
SomeFunction() *third_party.UnderlyingType
}
type MockClient struct {
third_party.Client
}
// Forced to return the third party non-interface type 'UnderlyingType'
func (f *MockClient) SomeFunction() *UnderlyingType {
// No way …Run Code Online (Sandbox Code Playgroud)