在Jackson根据官方文档添加自定义序列化程序后,我观察到了略微不同的json输出格式.
这个例子是基于弹簧垫的叉子.
扩展org.springsource.restbucks.WebConfiguration从RepositoryRestMvcConfiguration并重写configureJacksonObjectMapper:
@Override
protected void configureJacksonObjectMapper(ObjectMapper objectMapper) {
final SimpleSerializers serializers = new SimpleSerializers();
serializers.addSerializer(Order.class, new OrderSerializer());
objectMapper.registerModule(new SimpleModule("CustomSerializerModule"){
@Override public void setupModule(SetupContext context) {
context.addSerializers(serializers);
}
});
}
Run Code Online (Sandbox Code Playgroud)
创建类org.springsource.restbucks.order.OrderSerializer.为简洁起见,只需将属性写paid为JSON即可.
public class OrderSerializer extends JsonSerializer<Order> {
@Override
public void serialize(Order value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
jgen.writeBooleanField("paid", value.isPaid());
jgen.writeEndObject();
}
}
Run Code Online (Sandbox Code Playgroud)
在添加OrderSerializer json响应之前,http://localhost:8080/orders/1看起来像:
{
"location": "TAKE_AWAY", …Run Code Online (Sandbox Code Playgroud) 我正在开发一个具有以下要求的Web应用程序:
我正在为web应用程序使用spring-mvc和spring security.所以,我得到了一个解决方案,但是我刚接触弹簧并且不确定解决方案是否正确.
有人可以建议:
谢谢 :)
方案:
我创建了一个MyUser对象,它将存储从REST服务收到的其他信息.
public class MyUser implements Serializable {
private static final long serialVersionUID = 5047510412099091708L;
private String RestToken;
private String RestKey;
public String getRestToken() {
return RestToken;
}
public void setRestToken(String restToken) {
RestToken = restToken;
}
public String getRestKey() {
return RestKey;
}
public void setRestKey(String restKey) {
RestKey = restKey;
}
}
Run Code Online (Sandbox Code Playgroud)然后我创建了一个扩展UsernamePasswordAuthenticationToken的MyAuthenticationToken对象.此对象将在CustomAuthenticationProvider中使用(下面的第3点).
public class MyAuthenticationToken extends UsernamePasswordAuthenticationToken {
private static …Run Code Online (Sandbox Code Playgroud)如何使用Spring security 2和Apache Tomcat 7设置将JSESSIONID cookie设置为安全.
已经在web.xml中放入了下面的代码,它似乎并没有起作用.
<cookie-config>
<secure>true</secure>
</cookie-config>
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试使用spring rest模板来发布登录请求.
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
LinkedMultiValueMap<String, Object> mvm = new LinkedMultiValueMap<String, Object>();
mvm.add("LoginForm_Login", "login");
mvm.add("LoginForm_Password", "password");
ResponseEntity<String> result = restTemplate.exchange(uriDWLogin, HttpMethod.POST, requestEntity, String.class);
Run Code Online (Sandbox Code Playgroud)
一切顺利,但当我尝试发送第二个请求时,它会生成错误说:
业务经理在15分钟后关闭您的会话
我该怎么做才能解决这个问题?
我需要使用XMLUnit 2xml 子节点顺序不同的位置来比较 XML 文件。由于使用了底层库,我无法影响子节点的顺序。
为了进行比较,我正在使用:
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.0.0-alpha-02</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<version>2.0.0-alpha-02</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题归结为这个 JUnit 测试:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.builder.Input.fromString;
import static org.xmlunit.diff.ElementSelectors.byName;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.xmlunit.diff.DefaultNodeMatcher;
import java.io.IOException;
public class XmlTest {
@Test
public void test() throws Exception {
String t1 = fromClassPath("t1.xml");
String t2 = fromClassPath("t2.xml");
assertThat(fromString(t1), isSimilarTo(fromString(t2)).withNodeMatcher(new DefaultNodeMatcher(byName)));
}
private static String fromClassPath(String fileName) throws IOException {
return IOUtils.toString(new ClassPathResource(fileName).getInputStream());
} …Run Code Online (Sandbox Code Playgroud) 我在我的 Oracle 数据库上写了一个触发器,但它显示了这个错误:
Compilation failed, line 11 (17:21:05) The line numbers associated
with compilation errors are relative to the first BEGIN statement.
This only affects the compilation of database triggers. PL/SQL:
ORA-00923: FROM keyword not found where expectedCompilation failed,
line 11 (17:21:05) The line numbers associated with compilation errors
are relative to the first BEGIN statement. This only affects the
compilation of database triggers. PL/SQL: SQL Statement ignored
Run Code Online (Sandbox Code Playgroud)
这是代码:
CREATE OR REPLACE TRIGGER BEGIN_CALL1 AFTER INSERT ON STATE_CHANGE
FOR EACH …Run Code Online (Sandbox Code Playgroud) D:\ HYBRIS软拷贝\ hybris\bin\platform> setantenv.bat
将ant home设置为:D:\ HYBRIS软拷贝\ hybris\bin\platform\apache-ant-1.9.1 Apache Ant(TM)1.9.1版于2013年5月15日编译
D:\HYBRIS Soft copies\hybris\bin\platform>ant clean all
Buildfile: D:\HYBRIS Soft copies\hybris\bin\platform\build.xml
[echo] D:\HYBRIS Soft copies\hybris\bin\platform/tomcat/bin
[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\log
[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\data
[mkdir] Created dir: D:\HYBRIS Soft copies\hybris\temp\hybris
[input]
[input] **** NO CONFIG FOLDER FOUND ****
[input]
[input] No config folder was found at D:\HYBRIS Soft copies\hybris\config.
[input] A "fresh" folder containing basic configuration files and the hybris
[input] demo licence will be created for your convenience. …Run Code Online (Sandbox Code Playgroud)