小编dat*_*ree的帖子

当我只想使用RestTemplate时,如何防止在Spring Boot中自动启动tomcat/jetty

我想通过在SpringBoot应用程序中包含工件来使用RestTemplate/TestRestTemplate

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

但这会自动启动Tomcat或Jetty.有没有办法将其关闭,或者不包括上述工件.TestRestTemplate位于引导工件中,但不是基础RestTemplate.

java spring resttemplate spring-boot

21
推荐指数
2
解决办法
1万
查看次数

HashMap不可序列化

HashMapSerializable键/值应该是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)

java hashmap serializable

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

hashmap ×1

resttemplate ×1

serializable ×1

spring ×1

spring-boot ×1