小编Spr*_*ing的帖子

在Eclipse上安装和使用jersey

在我的Web服务中,我使用eclipse,java 1.5,spring.现在我想使用针对REST的球衣,并从这个地址下载了作为捆绑罐的球衣:

http://jersey.java.net/nonav/documentation/latest/chapter_deps.html

如何将这个jar添加到我的项目并开始使用JAX-rs注释,我添加到buildpath但似乎不起作用.

是否有必要或者一个好主意创建我的资源类的JAXB注释类并将它们与JERSEY一起使用?

java spring jax-rs jaxb jersey

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

找不到 WSDL 文件架构位置

在尝试使用 soapUI 时,我收到错误消息,说它无法加载架构 request.xsd 这里是我的 wsdl 的样子:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
              xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
              xmlns:schema="http://www.myweb/xml/webservice"
              xmlns:tns="http://www.myweb.com/xml/webservice"
              targetNamespace="http://www.myweb.com/xml/webservice">
<wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:import namespace="http://www.myweb.com/xml/webservice"                      
            schemaLocation="/WEB-INF/schemas/Request.xsd"/>
    </xsd:schema>
Run Code Online (Sandbox Code Playgroud)

这是我的 spring 配置文件的方式:

   <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"   
xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<bean id="payloadMapping"   class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    <property name="defaultEndpoint" ref="inferenceEndPoint" />
    <property name="interceptors">
        <list>
            <ref local="validatingInterceptor" />
            <ref local="payLoadInterceptor" />
        </list>
    </property>
</bean>

<bean id="payLoadInterceptor"
    class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />

<bean id="validatingInterceptor"
    class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    <description>
        This interceptor validates the incoming
        message contents
        according to …
Run Code Online (Sandbox Code Playgroud)

java spring wsdl web-services

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

使用Collections.emptyList()和null处理

说到在Java中处理"空值"的最佳实践(特别是"List"返回),从实体类的getMethod返回"Collections.emptyList()"是一个好习惯吗?或者我们应该保持实体/数据类/方法干净整洁,并始终返回其值(即使是null),然后在代码中的其他位置处理该null,例如;

Class Reference{

private Reference reference;

@XmlElement(name = "Reference")
public List<Reference> getReference() {
    if(reference==null){
        return Collections.emptyList();
    }
    return reference;
}

public void setReference(List<Reference> reference) {
    this.reference = reference;
}
}
Run Code Online (Sandbox Code Playgroud)

或者更好地处理那个"之后"我使用基本的get方法?

编辑/警告:仅仅针对我的场景,我注意到这种方法会使我的代码崩溃我不知道为什么,当我后来打电话时;

References ref= (References) jaxbUnmarshaller.unmarshal(xmlReader)
Run Code Online (Sandbox Code Playgroud)

我得到了一个不受支持的操作异常,但是当我从collections.emtpyList清理我的getMethod时工作正常.使用@XmlElement标记时要小心

java null

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

通过Rest下载CSV文件

使用OpenCSV,我可以在光盘上成功创建一个CSV文件,但我真正需要的是允许用户使用下载按钮下载CSV,我不需要保存在磁盘上,只需下载即可.有任何想法吗?

@GET
@Path("/downloadCsv")
public Object downloadCsv() {
        CSVWriter writer;
        FileWriter wr; 
      //Or should I use outputstream here?   
        wr= new FileWriter("MyFile.csv");
        writer = new CSVWriter(wr,',');
        for (Asset elem: assets) {
            writer.writeNext(elem.toStringArray());
        }
        writer.close();


}
Run Code Online (Sandbox Code Playgroud)

编辑:我不想在光盘上保存/读取文件EVER

java csv rest opencsv

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

我的导出文件中缺少Oracle,Blob数据

我使用Oracle 11g,我试图导出我的数据(只有数据,而不是表创建脚本等)所以它可以被客户导入他们的数据库

当我使用Oracle Sql开发人员的导出数据库时,它只导出数据但我的BLOB缺失了!我的一个表中有很多图像文件,我也想导出.

我想知道我真的需要使用oracle exp imp工具;

http://docs.oracle.com/cd/B28359_01/server.111/b28319/exp_imp.htm#i1004777

任何的想法?

oracle oracle11g data-export oracle-sqldeveloper

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

用于HTTP 400的Spring MVC自定义消息

我有几个如下所示的SprigMVC方法,返回ModelAndView或Responsebody.当用户向这些URL发出缺少所需参数的请求时,他们自然会收到消息"必需字符串参数'id'不存在".

从安全角度来看,我想隐藏用户的详细描述消息.因此,黑客不容易知道缺少的参数,并且在没有任何描述的情况下会得到400错误.这可能是通过弹簧配置/ Spring Security实现的,或者我必须手动重构我的所有方法以某种方式返回自定义消息.

@RequestMapping(value = "/payment", method = RequestMethod.GET)
public ModelAndView getReponse(@RequestParam(value = "id", required = true)) {

    return model;
}

@RequestMapping(value = "/status", method = RequestMethod.GET)
public @ResponseBody String getStatus(@RequestParam(value = "id", required = true) String id) {

    return "string";
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

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

Springboot 2.2 迁移出现 flyway 错误:发现多个版本的迁移

Springboot 2.2.0.RELEASE,Flyway 版本 6.0.6

我正在尝试迁移到 Spring Boot 2.2。但是当我启动应用程序时,我遇到了飞行错误。(mvn clean install 工作正常)我的解释是它无法正确读取位置,所以它认为文件是重复的。实际上,在不同的文件夹中。

spring.flyway.locations=classpath:db/migration/common,classpath:db/migration/{vendor}
Run Code Online (Sandbox Code Playgroud)

错误:

在 16.0 版中发现了多个迁移

违规者:../target/classes/db/migration/h2/V16.0__spring_batch_schema.sql (SQL) ../target/classes/db/migration/oracle/V16.0__spring_batch_schema.sql (SQL)

java flyway spring-boot

5
推荐指数
0
解决办法
278
查看次数

当数据源发生变化时,如何刷新UI Picker View?

当数据源(数组)发生变化时,如何刷新UI Picker View?

iphone objective-c ios4

4
推荐指数
1
解决办法
2852
查看次数

Angular js不起作用

这是我的html文件.angular.js文件位于java/main/webapp/js文件夹下,当我点击它时,Intellij可以看到它,但代码不起作用!我在屏幕{{helloMessage}}上打印,而不是"hello world"

我在这里错过了什么?

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Angular test </title>

</head>
 <body>

<h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1>

Angular test 
<script src="js/angular.js"> </script>
<script type="text/javascript">

  function HelloWorldCtrl($scope){
       $scope.helloMessage="Hello World";
  }

</script >

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript angularjs

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

Spring websockets:消息未发布

我将 Spring WebSockets 与 STOMP 和 SockJS 用于前端。它工作正常,但我还有另一个困难。

这是后端代码:

 @MessageMapping("/showAccountlist")
 @SendTo("/topic/accounts")
 public Account createPublishAccount(String name) throws Exception {

     return new Account(name);
 }
Run Code Online (Sandbox Code Playgroud)

这是前端代码,运行良好,所有消息都发布到所有客户端。

 stompClient.send("/app/showAccountlist", {}, name);
Run Code Online (Sandbox Code Playgroud)

但是当我我的 java 后端调用我的后端方法时,使用方法名称

createPublishAccount("Carlos");
Run Code Online (Sandbox Code Playgroud)

似乎消息没有发布。有什么解决办法吗?或者这不是它的工作方式,它仅在通过 SockJS 触发时才有效?

这是我的网络配置:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer  {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/topic");
    config.setApplicationDestinationPrefixes("/app");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/showAccountlist").withSockJS();
}
Run Code Online (Sandbox Code Playgroud)

}

java spring stomp websocket spring-websocket

4
推荐指数
1
解决办法
1953
查看次数