我试图用来spring-boot-starter-web
创建一个提供Java对象的JSON表示的休息服务.根据我的理解,这个boot-starter-web jar应该自动处理通过Jackson转换为JSON,但我得到了这个错误.
{ "timestamp": 1423693929568,
"status": 406,
"error": "Not Acceptable",
"exception": "org.springframework.web.HttpMediaTypeNotAcceptableException",
"message": "Could not find acceptable representation"
}
Run Code Online (Sandbox Code Playgroud)
我的控制器就是这个......
@RestController
@RequestMapping(value = "/media")
public class MediaController {
@RequestMapping(value = "/test", method = RequestMethod.POST)
public @ResponseBody UploadResult test(@RequestParam(value="data") final String data) {
String value = "hello, test with data [" + data + "]";
return new UploadResult(value);
}
@RequestMapping(value = "/test2", method = RequestMethod.POST)
public int test2() {
return 42;
}
@RequestMapping(value = "/test3", method = RequestMethod.POST)
public …
Run Code Online (Sandbox Code Playgroud) 我目前有一台服务器在Tomcat servlet中使用Shiro Token系统运行Spring,用于检查用户是否已经登录.它允许跨域请求.
在任何其他域我可以在客户端(通常使用角度)调用...
http.get('https://<my_check_login_service>', {withCredentials: true})
...只要我已经登录(令牌未过期),就会返回用户信息(姓名,头像等).
我现在有另一个系统,它是一个节点服务器(也为客户端提供角度),我想称之为节点服务器并让它代理到上面的my_check_login_service以获取用户,在会话对象上设置信息(使用快递),然后将用户返回给客户端.而且,通过会话对象,让我相信自己的连接,并允许他们执行取决于从登录服务返回的用户的安全水平进一步API调用.
在node.js路由器上我可以代理这样做......
app.get('/checklogin', function(req, res) {
req.pipe(request.get("https://<my_check_login_service>").pipe(res);
}
Run Code Online (Sandbox Code Playgroud)
...但我不知道如何将正确的凭据传递给服务.如果我做 ...
http.get('checkLogin', {withCredentials: true})
...当然,它不起作用,因为我的login_service的凭据不会发送到本地服务器.如何通过正确的凭据才能使其正常工作?
干杯.
当我尝试npm install
在 Windows上运行时,出现以下错误。怎样才能摆脱它?
D:\Xampp\htdocs\laravelchat>npm install
'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud) 我一直遇到问题,一直使用Spring Boot和Jackson-databind 2.5.2将Joda DateTime从java序列化和反序列化为json,然后再将其反序列化.我的pom.xml看起来像这样.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我序列化DateTime对象时,我得到一个表示DateTime的整数.不是我的预期,但很好.但是当我去保存我的对象时,我得到以下错误...
Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.DateTime' for property 'endTime';
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type org.joda.time.DateTime for value '1428600998511'
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它将序列化为一个整数,然后将其反序列化,就像它是一个字符串,它不是.我还尝试在调用其余服务之前设置endTime = new Date(intValue),并且尝试将字符串转换为类似'Tue Apr 28 2015 00:00:00 GMT-0700(PDT)'的字符串也失败了.
我究竟做错了什么?
更新:
下面是我得到的JSON 和我试图立即发布右后卫.
{
id: 4,
username: "",
name: "eau",
email: "aoue",
verbatimLocation: null,
latitude: null,
longitude: null, …
Run Code Online (Sandbox Code Playgroud) 使用angular 2.0.1(发布)和ng2-file-upload 1.1.0(最新版本)运行此代码时出现上述错误.我正在使用带有systemjs的jspm来捆绑我的应用程序(所有这些都是最新的).
import {Component, NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FileUploadModule} from 'ng2-file-upload';
@Component({
selector: 'uploader',
templateUrl: '/build/templates/uploader.html'
})
export class UploaderComponent {
uploader = new FileUploader({url: '/upload'});
hasBaseDropZoneOver = false;
fileOverBase(event) {
this.hasBaseDropZoneOver = event;
}
clearQueue() {
this.uploader.clearQueue();
}
}
console.log(FileUploadModule);
@NgModule({
imports: [CommonModule, FileUploadModule],
declarations: [UploaderComponent],
exports: [UploaderComponent]
})
export class UploaderModule {};
Run Code Online (Sandbox Code Playgroud)
如果我检查FileUploadModule的值,它看起来非常好,就像它看起来就像我检查过的所有其他模块一样.我的应用程序中还有其他所有功能,但这一部分.这个模块的"意外"是什么?
完整错误:
错误:(SystemJS)模块'UploaderModule'(...)导入的意外值'FileUploadModule'
这是FileUploadModule导出的相对部分,对我来说很好
var FileUploadModule = (function() {
function FileUploadModule() {}
FileUploadModule = __decorate([core_1.NgModule({
imports: [common_1.CommonModule],
declarations: [file_drop_directive_1.FileDropDirective, file_select_directive_1.FileSelectDirective],
exports: …
Run Code Online (Sandbox Code Playgroud) 我发现 Tomcat 8 和 Tomcat 9 之间的文件权限发生了变化,我不知道如何解决它。
我有这样的代码,其中 inputStream 是我提供给这个例程的东西,而 redirectStream 是一个函数,它只使用 BufferedInput 和 BufferedOutput 流从一个流读取到另一个流。
Path path = "/some/example/path/to/a/file";
Files.createDirectories(path.getParent());
redirectStream(inputStream, new FileOutputStream(path.toFile());
在 Tomcat8 中执行这段代码后,目录和文件的权限将与用户的 umask (0022) 匹配。那就是目录将具有drwxr-xr-x
,文件将具有-rw-r--r--
. 由于它正在写入的这些文件随后可被 Internet 访问,因此需要全局读取标志。
但是在 Tomcat9 下,相同的代码分别给出了drwxr-x---
和-rw-r-----
,因此在互联网上是不可见的。我尝试了两件事。一个我在我的 tomcat 启动脚本中明确地将 umask 设置为 0022 只是为了确保它是无效的。第二种是在代码中显式设置权限以尝试强制问题。这修复了文件权限但不是目录权限,下面是更新的代码。
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
Files.createDirectories(path.getParent(), PosixFilePermissions.asFileAttribute(perms));
redirectStream(inputStream, new FileOutputStream(path.toFile());
perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_WRITE);
perms.add(PosixFilePermission.OTHERS_READ);
Files.setPosixFilePermissions(fullPath, perms);
Run Code Online (Sandbox Code Playgroud)
这实际上修复了文件的文件权限,而不是目录的文件权限。我已经在 …
我正在使用包含jsr310数据类型的带有杰克逊2.6.2的spring-boot 1.2.1.RELEASE。我正在使用批注@SpringBootApplication启动Spring应用程序。我有
spring.jackson.serialization.write_dates_as_timestamps = false
Run Code Online (Sandbox Code Playgroud)
在我的application.properties中设置(我知道它正在读取,因为我使用banner = false进行了测试)。
然而,java.time.LocalDate仍被序列化为整数数组。我没有使用@EnableWebMvc。
好像我添加了标签
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")
Run Code Online (Sandbox Code Playgroud)
到我的LocalDate变量,然后它可以工作。但是我以为上面的属性集是自动的。另外,如果我没记错的话(从那以后我就决定使用整数数组),那只适用于序列化而不是反序列化(但是我不能坦白地记得最后一部分是否正确)。
我正在打包为 war 文件的 Tomcat 实例中运行 Spring Boot 应用程序。我希望能够以休息服务的形式将“包”添加到我的实例中。为此,我需要能够在运行时在 @SpringBootApplication 注释中配置 scanBasePackages。即当tomcat启动时。现在我有...
@SpringBootApplication(scanBasePackages="path1, path2")
public class RestApplication extends SpringBootServletInitializer {
//code
}
Run Code Online (Sandbox Code Playgroud)
...但我希望 path2 是可配置的,并且如果需要的话也可以添加 path3 等。我怎样才能实现这个目标?我知道我无法在注释中配置字符串,所以我的问题是我对该注释还有哪些其他替代方案来设置它。
干杯。