小编Vis*_*cha的帖子

spring boot:java.lang.IllegalArgumentException:object不是声明类的实例

我已经设置了一个spring boot项目并使用castor xml依赖项将POJO转换为xml.

compile 'org.codehaus.castor:castor-xml:1.3.3'
Run Code Online (Sandbox Code Playgroud)

在为POJO调用marshal方法时遇到问题.我已经在stackoverflow上查找了其他相关问题,但没有一个有我的方案的解决方案.

在弹簧组件内部有toString方法.

这是片段:

public String toString(Client client) throws MarshalException, org.exolab.castor.xml.ValidationException {
    String xml = null;

    // Create the xml
    StringWriter sw = new StringWriter();
    client.marshal(sw);
    xml = sw.toString();

    return xml;
  }
Run Code Online (Sandbox Code Playgroud)

这里是客户端内部的marshal方法(之前由castor自动生成的类):

public class Client implements java.io.Serializable {

      private static final long serialVersionUID = 5203108777533793020L;
      private Object _clientId;
      private String _someOtherField;
      private List<Address> _addresses; // this is also serialized;

       public void marshal(final java.io.Writer out) throws org.exolab.castor.xml.MarshalException,org.exolab.castor.xml.ValidationException{
               Marshaller.marshal(this, out);
        }
Run Code Online (Sandbox Code Playgroud)

这是相同的堆栈跟踪:

java.lang.IllegalArgumentException: object is not an …
Run Code Online (Sandbox Code Playgroud)

java castor jaxb spring-boot

7
推荐指数
1
解决办法
340
查看次数

由于升级标头无效,Spring 启动 Websockets 握手失败:null

我正在使用 spring boot 2.1.6 RELEASE,尝试使用 Stomp websockets 进行推送通知。我从这里参考: https: //github.com/netgloo/spring-boot-samples/tree/master/spring-boot-web-socket-user-notification

在我当地一切正常。当部署到具有 HTTPS 连接的服务器时,我在日志中看到的只是此内容。

Handshake failed due to invalid Upgrade header: null
Run Code Online (Sandbox Code Playgroud)

并在浏览器上

Websocket.js:6 WebSocket connection to 'wss://dev.myserver.in/ws/055/chbvjkl4/websocket' failed
Run Code Online (Sandbox Code Playgroud)

我浏览了数十篇 stackoverflow 帖子,几乎每个人都在使用代理服务器。我没有使用任何代理服务器。(请告诉我是否应该使用它以及为什么)

代码片段:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").withSockJS();
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我现在允许 websocket 请求的方式

@Override
    public void configure(WebSecurity web) throws Exception {

        // Tell Spring to ignore securing the handshake endpoint. This allows the
        // handshake to take place unauthenticated
        web.ignoring().antMatchers("/ws/**");

    } …
Run Code Online (Sandbox Code Playgroud)

java stomp websocket sockjs spring-boot

5
推荐指数
1
解决办法
3542
查看次数

标签 统计

java ×2

spring-boot ×2

castor ×1

jaxb ×1

sockjs ×1

stomp ×1

websocket ×1