我正在尝试使用Spring-data-rest和spring-data-mongodb来公开只读资源.
我遇到的问题是,我希望对文档有不同的看法.假设我在文档中有一些私人信息,我不想公开公开它们.
所以我尝试了几种方法.我读了这篇文章https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring,描述了如何使用JsonView来选择我们想要公开的字段.
我试过这样的:
@RepositoryRestResource(collectionResourceRel = "recommandation", path = "recommandations")
interface RecommandationRepository extends MongoRepository<Recommendation, ObjectId> {
@Override
@JsonView(View.Public.class)
Iterable<Recommendation> findAll(Iterable<ObjectId> objectIds);
... // other find methods
}
Run Code Online (Sandbox Code Playgroud)
它不起作用.但是在评论中说:https ://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring#comment-1725671983答案建议使用@Projections但是@Projections结果在这样的URL中:".../recommandations {?projection}"这意味着投影只是一个选项,因此完整的对象仍然是暴露的.
这里描述了另一种方法https://github.com/spring-projects/spring-data-rest/wiki/Configuring-the-REST-URL-path 它建议对字段使用@RestResource(exported = false)注释我们不想暴露.
但它并不灵活.如果我想公开一个公共只读API和一个私有的完整访问API.每个api不能禁用此注释.
还有其他建议吗?
我正在使用Spring启动,之前我们使用Spring和Tomcat.两年前我们使用Spring和Tomcat时,我们使用maven插件来预编译jsp.在部署之后避免每次首次访问都要进行编译是非常有用的.
但是,我们知道的所有maven插件都会转储一个web.xml文件,该文件列出了所有jsp和相关的生成的servlet.使用Spring启动时,它不再使用web.xml,因此忽略此文件.
我们仍然有编辑,这是一个安全带,但每页第一次访问都会受到惩罚.
有人知道是否可以在Spring启动应用程序中预编译jsp?
我正在尝试使用Mongodb上的文本索引.
我已经在一个集合上使用了文本索引:
db.ensureIndex({field1 : "text"})
Run Code Online (Sandbox Code Playgroud)
它的工作原理.
但我重新审视了另一个集合,我收到以下消息:
db.movies.ensureIndex({genres: "text"})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"ok" : 0,
"errmsg" : "found language override field in document with non-string type",
"code" : 17261
}
Run Code Online (Sandbox Code Playgroud)
集合"movies"有一个"genres"字段,它是一个字符串数组.例如 :
> db.movies.findOne()
{
"_id" : ObjectId("51c460fdc30a209dd9621dc4"),
"genres" : [
"Crime",
"Drama"
]
...
}
Run Code Online (Sandbox Code Playgroud)
该字段出现在所有文档中.
我不明白这个错误.任何的想法 ?
我有一个由monit监控的spring-boot应用程序.Monit只是检查/ health端点弹簧是否暴露.
基本上,monit注册了以下检查:
check host hopsearch_connection with address 127.0.0.1
if failed url http://127.0.0.1:8089/health with timeout 15 seconds then alert
check host hopsearch_health with address 127.0.0.1
if failed url http://127.0.0.1:8089/health
and content != 'DOWN'
with timeout 60 seconds
then alert
Run Code Online (Sandbox Code Playgroud)
并且Web应用程序返回类似的内容:
{"status":"UP","jestHealth":{"status":"UP","lastQuerySuccess":true},"diskSpace":{"status":"UP","free":14439550976,"threshold":10485760},"rabbit":{"status":"UP","version":"3.3.2"},"redis":{"status":"UP","version":"3.0.0"},"mongo":{"status":"UP","version":"2.6.1"}}
Run Code Online (Sandbox Code Playgroud)
在这个spring应用程序中,我有一个通用的@ExceptionHandler来记录所有意外错误并显示错误页面:
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public String handleDefaultError(Exception ex, HttpServletRequest httpRequest) {
logException(httpRequest, ex);
return "error";
}
Run Code Online (Sandbox Code Playgroud)
这个@ExceptionHandler记录来自monit的每个调用:
<11>May 1 13:20:39 IP 13:20:39.339 t=http-nio-8089-exec-3 l=ERROR c=c.h.s.w.c.ErrorManager m=Error 500
----------------------------------------------------------------
Request Path=http://127.0.0.1:8089/health
Method=GET
----------------------------------------------------------------
Header :
----------------------------------------------------------------
host = 127.0.0.1:8089 …Run Code Online (Sandbox Code Playgroud) 我现在正在与redact斗争,我不确定理解它.
我只是阅读了文档并试图在集合等级上使用redact(它来自mongodb在线培训)
集合"成绩"中的文档如下所示:
{
"_id" : ObjectId("50b59cd75bed76f46522c34e"),
"student_id" : 0,
"class_id" : 2,
"scores" : [
{
"type" : "exam",
"score" : 57.92947112575566
},
{
"type" : "quiz",
"score" : 21.24542588206755
},
{
"type" : "homework",
"score" : 68.19567810587429
},
{
"type" : "homework",
"score" : 67.95019716560351
},
{
"type" : "homework",
"score" : 18.81037253352722
}
]
}
Run Code Online (Sandbox Code Playgroud)
我使用以下查询:
db.grades.aggregate([
{ $match: { student_id: 0 } },
{
$redact: {
$cond: {
if: { $eq: [ "$type" , "exam" ] …Run Code Online (Sandbox Code Playgroud) 我慢慢开始从 nuxt 2 迁移到 nuxt 3。以前我曾经使用 axios。
在Nuxt3中,推荐使用useFetch
然而,useFetch 的行为非常奇怪。呼叫不是系统进行的。
例如在这段代码中:
async mounted() {
const store = useAuth();
let response = await axios.get('http://dev.test.fr/api/secured/admin', {headers : store.authHeader() });
this.sensibleInformation = response.data;
},
Run Code Online (Sandbox Code Playgroud)
使用 Axios,每次我打开此页面时,都会进行调用并且 sensibleInformation 是最新的。
使用useFetch,语法类似
async mounted() {
const store = useAuth();
let response = await useFetch('http://dev.malt.fr/api/secured/admin' , {method : 'get', headers : store.authHeader() });
this.sensibleInformation = response.data;
},
Run Code Online (Sandbox Code Playgroud)
但有时对服务器的调用已经完成。因此,合理的信息大部分时间都是空的。而且我在文档中没有找到任何解释。
也许这里有我想念的东西。
我正在使用 nuxt 3.0.0-rc.6
我尝试使用Zuul,一个在Spring Cloud Netflix中使用的反向代理.我从春季博客上的教程(https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v)开始了一个项目
然而,我不确定我是否正确地理解了Zuul的角色.
如果我去localhost:8080 /登录,我认为Zuul会代理我的请求,以便我留在localhost:8080但我有一个302重定向到localhost:9999/uaa/login.
配置的zuul路由如下:
zuul:
routes:
resource:
path: /resource/**
url: http://localhost:9000/resource
login:
path: /login/**
url: http://localhost:9999/uaa/login
user:
path: /user/**
url: http://localhost:9999/uaa/user
auth:
path: /auth/**
url: http://localhost:9999/uaa/
是否有可能永远留在localhost:8080(这是我认为Zuul应该做的)?
整个项目在github上可用,因此可以在本地运行:https://github.com/hlassiege/oauth-social-zuul
我正在使用 Spring 的 RestTemplate 来查询搜索服务。而且我在正确序列化方面遇到了一些困难。如果我使用这个方法,restTemplate 会返回一个列表。我不明白如何传递参数化类型
UriBuilder builder = UriBuilder.fromUri(uri+ "/search");
builder = builder.queryParam("category", category);
HttpEntity<String> request = new HttpEntity<>(createHeaders(user, pwd));
ResponseEntity<List> search = searchTemplate.exchange(builder.build().toString(), HttpMethod.GET, request, List.class);
return search.getBody();
Run Code Online (Sandbox Code Playgroud)
PS:我已经尝试过 GeoPriceStats[].class 而不是 List.class
任何的想法 ?
我正在使用spring boot 1.2.2.它是一个使用jsp的标准Web应用程序,并作为可执行的战争运行:Java -jar myapp.war.
当我在桌面上运行此应用程序时,一切都很好.但是,在我们使用的服务器(Debian)上它真的很慢.
我收集了一些线程转储,我看到一些奇怪的东西.似乎应用程序在编译jsp时遇到了一些麻烦(参见下面的stacktraces).
似乎jsp总是被重新编译.有谁知道会出现什么问题?
"http-nio-8443-exec-8" #50 daemon prio=5 os_prio=0 tid=0x000000000288f800 nid=0x7452 runnable [0x00007fd611adc000]
java.lang.Thread.State: RUNNABLE
at java.lang.Throwable.fillInStackTrace(Native Method)
at java.lang.Throwable.fillInStackTrace(Throwable.java:783)
- locked <0x00000000ec2eb250> (a java.io.FileNotFoundException)
at java.lang.Throwable.<init>(Throwable.java:265)
at java.lang.Exception.<init>(Exception.java:66)
at java.io.IOException.<init>(IOException.java:58)
at java.io.FileNotFoundException.<init>(FileNotFoundException.java:64)
at org.springframework.boot.loader.jar.JarURLConnection.throwFileNotFound(JarURLConnection.java:118)
at org.springframework.boot.loader.jar.JarURLConnection.connect(JarURLConnection.java:107)
at org.springframework.boot.loader.jar.JarURLConnection.getInputStream(JarURLConnection.java:175)
at sun.misc.URLClassPath$Loader.findResource(URLClassPath.java:516)
at sun.misc.URLClassPath.findResource(URLClassPath.java:176)
at java.net.URLClassLoader$2.run(URLClassLoader.java:557)
at java.net.URLClassLoader$2.run(URLClassLoader.java:555)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:554)
at org.springframework.boot.loader.LaunchedURLClassLoader.findResource(LaunchedURLClassLoader.java:78)
at org.springframework.boot.loader.LaunchedURLClassLoader.getResource(LaunchedURLClassLoader.java:69)
at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:232)
at org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1096)
at org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:142)
at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:197)
at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:182)
at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:158)
at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getType(PackageBinding.java:145)
at org.eclipse.jdt.internal.compiler.lookup.Scope.findType(Scope.java:2038)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3350)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:2304) …Run Code Online (Sandbox Code Playgroud) spring-boot ×4
mongodb ×2
spring ×2
spring-mvc ×2
java ×1
jsp ×1
maven ×1
monit ×1
netflix-zuul ×1
nuxtjs3 ×1
resttemplate ×1
spring-cloud ×1