我已多次阅读文档(http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/testing.html#spring-mvc-test-framework),我可以确认WebApplicationContext在使用@WebApplicationContext注释时注入的上下文是否实际上是在查看web.xml.
换句话说,我想测试我的web.xml配置.特别是过滤器和servlet路径.但是当我配置我的测试时,它会忽略web.xml.(例如,我get在这样的URL上尝试请求/myServletPath/foo,但它失败了404.)
我的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
"classpath*:WEB-INF/config/application-context.xml",
"classpath*:WEB-INF/oms-servlet.xml",
"classpath*:persistence-context.xml"
})
public class OrderSummaryControllerIntegrationTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setUp() throws Exception {
this.mockMvc = webAppContextSetup(this.wac).build();
}
@Test
public void testFindOrderSummariesExpectsSuccess() throws Exception {
mockMvc.perform(get("/oms/orders?user=1234&catalog=bcs"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
}
Run Code Online (Sandbox Code Playgroud)
还有我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="2.5">
<display-name>OMS REST Services</display-name>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<filter>
<filter-name>webappMetricsFilter</filter-name>
<filter-class>com.yammer.metrics.web.DefaultWebappMetricsFilter</filter-class>
</filter> …Run Code Online (Sandbox Code Playgroud) spring integration-testing web.xml spring-mvc spring-test-mvc
我正在尝试动态创建一个结构片段,我可以将我的数据封送到其中,但是在运行时根据一些未知的结构类型进行.我这样做是因为我希望有一个共同的代码可以解组任何实现特定接口的代码.
例如(伪代码)
func unmarshalMyData(myInterface MyInterface, jsonData []byte) {
targetSlice := myInterface.EmptySlice()
json.Unmarshal(jsonData, &targetSlice)
}
Run Code Online (Sandbox Code Playgroud)
我尝试过几种不同的选择.看起来最有希望的是使用reflect包构建切片.不幸的是,在解组后,动态创建的切片的类型为[]interface{}.如果我在解组之前打印出动态创建的切片的类型,则会打印出来[]*main.myObj.有谁能解释为什么?请参阅游乐场链接:https://play.golang.org/p/vvf1leuQeY
有没有其他方法可以动态创建一个正确解组的结构片?
我知道json.RawMessage,但有一些原因我无法使用它......我的json中没有"type"字段.此外,我解组的代码没有编译时知道它解组的结构.它只知道struct实现了一个特定的接口.
有些代码让我感到困惑,为什么动态创建的切片在解组后不会保持其类型:
package main
import (
"encoding/json"
"fmt"
"reflect"
)
func main() {
input := `[{"myField":"one"},{"myField":"two"}]`
myObjSlice := []*myObj{}
fmt.Printf("Type of myObjSlice before unmarshalling %T\n", myObjSlice)
err := json.Unmarshal([]byte(input), &myObjSlice)
if err != nil {
panic(err)
}
fmt.Printf("Type of myObjSlice after unmarshalling %T\n", myObjSlice)
myConstructedObjSlice := reflect.MakeSlice(reflect.SliceOf(reflect.TypeOf(&myObj{})), 0, 0).Interface()
fmt.Printf("Type of myConstructedObjSlice before …Run Code Online (Sandbox Code Playgroud) 我想在开发中运行SQLite数据库,在生产中运行SQLServer Express数据库.
我们首先使用代码进行数据库迁移.
如何在每个环境中注入不同的dbcontext?
如何针对特定数据库运行迁移.例如,在开发中,我想要针对SQLite数据库运行迁移.
sqlite entity-framework entity-framework-6 .net-core asp.net-core
我正在使用此处记录的gradle artifactory发布插件:http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin
我完全按照文档中的说明使用标准配置.
当我从命令行运行gradle publishArtifactory任务时,我得到这样的输出.即它部署到我正确的模块名称.
Deploying artifact: http://<my server>/artifactory/libs-snapshot-local/<my actual module name>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war
Run Code Online (Sandbox Code Playgroud)
当我配置Jenkins gradle publishArtifactory使用相同的gradle构建文件运行任务时,我得到这样的输出.即它使用Jenkins构建作为模块名称.
Deploying artifact: http://artifactory01.bcinfra.net:8081/artifactory/libs-snapshot-local/<the name of the jenkins build>/web/0.1-SNAPSHOT/web-0.1-SNAPSHOT.war
Run Code Online (Sandbox Code Playgroud)
关于如何防止神器插件使用Jenkins构建名称作为模块名称的任何想法?
.net-core ×1
artifactory ×1
asp.net-core ×1
go ×1
gradle ×1
jenkins ×1
maven ×1
spring ×1
spring-mvc ×1
sqlite ×1
web.xml ×1