我想通过在SpringBoot应用程序中包含工件来使用RestTemplate/TestRestTemplate
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但这会自动启动Tomcat或Jetty.有没有办法将其关闭,或者不包括上述工件.TestRestTemplate位于引导工件中,但不是基础RestTemplate.
HashMap与Serializable键/值应该是Serializable.
但这对我不起作用.尝试了一些其他IO流.没有用.
有什么建议吗?
测试代码
public class SimpleSerializationTest {
@Test
public void testHashMap() throws Exception {
HashMap<String, String> hmap = new HashMap<String, String>() {{
put(new String("key"), new String("value"));
}};
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
out = new ObjectOutputStream(bos);
out.writeObject(hmap);
byte[] yourBytes = bos.toByteArray();
if (out != null) {
out.close();
}
bos.close();
ByteArrayInputStream bis = new ByteArrayInputStream(yourBytes);
ObjectInput in = null;
in = new ObjectInputStream(bis);
Object o = in.readObject();
bis.close();
if (in != …Run Code Online (Sandbox Code Playgroud)