我正在使用MongoDB尝试spring-data中的反应支持.我使用的是spring-boot 2.0.0.
通常我会在我的项目中写一个这样的域对象:
@Document
public class PriceData {
......
}
Run Code Online (Sandbox Code Playgroud)
使用这个spring-data,它将在MongoDB中创建一个名为priceData的集合.如果我想自定义它,那么我会使用collection属性来做:
@Document(collection = "MyPriceData")
Run Code Online (Sandbox Code Playgroud)
由于我想尝试MongoDB的反应支持,我想创建一个上限集合,以便我可以使用@Tailable游标查询.
我可以在我的MongoDB数据库中创建一个封顶集合作为指定在这里:
CollectionOptions options = new CollectionOptions(null, 50, true);
mongoOperations.createCollection("myCollection", options);
Run Code Online (Sandbox Code Playgroud)
要么
db.runCommand({ convertToCapped: 'MyPriceData', size: 9128 })
Run Code Online (Sandbox Code Playgroud)
如果我使用一些外部MongoDB数据库,我可以运行此命令一次,这不是一个大问题.但是如果我使用嵌入式MongoDB,那么我会把它放在一个每次启动时都要执行的类中.
无论哪种方式,我都会在第一次请求之前创建一个集合.所以我想知道是否有办法,我可以指定spring-data-mongodb我需要一个上限集合而不是常规集合.不幸的是@Document在这种情况下无济于事.
spring mongodb spring-data-mongodb spring-boot capped-collections
常规 Spring (Boot) 是否有办法进行全局异常处理,或者至少可以捕获任何未捕获的异常(例如RuntimeException可能随机发生的异常)?
我已经用谷歌搜索过,但我发现的所有内容都谈到了@ControllerAdvice @ExceptionHandlerfor 控制器。与一般的全局异常处理程序无关。
我基本上只是想确保如果发生一些我尚未捕获的异常,我会记录它以便我知道它。
我想实现一个删除集合中所有文档的删除方法。我在 Spring Data 中使用 mongo db。这可以在 Mongo shell 中使用 db.myCollection.remove({}) 来完成。但是我想在我的数据访问层中编写一个方法来做到这一点。我没有在我的 Dao 类中使用 MongodbTemplate。我想知道如何使用 Query 执行此操作。
Query query = new Query();
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我该怎么做。
我花了好几个小时在spring数据中找到QueryDslPredicateExecutor.为什么它是一个博客,但被称为QueryDslPredicateExecutor在文档QuerydslPredicateExecutor(小d!)神器2.0.4.RELEASE?哪个版本是正确的?
注释的使用有什么不同吗?这两个注释都允许使用多个@Configuration类来创建ApplicationContext.从他们的文档@ContextConfiguration似乎更适合测试配置,并来自测试(spring-test)的工件,但是,我没有找到实际的差异.
谢谢你的任何想法!
在我的春季启动应用程序中,我使用Jackson通过注入ObjectMapper所需的位置来序列化对象.我找到了这个答案:https://stackoverflow.com/a/32842962/447426
但是这个创建了一个新的映射器 - 带有jacksons默认设置.
另一方面,我在官方文件中发现了这一点.我真的不明白.没有示例代码.
那么如何在Springs默认对象映射器的基础上配置弹簧ObjectMapper?
注入时,此配置应在"ObjectMapper"上处于活动状态.
如何从对象获取List?您可以在下面找到我的代码:
ResponseEntity<Object> responseEntity = restTemplate.getForEntity("localhost:8083/connectors/", Object.class);
Object object = responseEntity.getBody();
Run Code Online (Sandbox Code Playgroud)
实际上,对象变量是一个对象列表(字符串),我需要获取所有这些字符串.
如果我将其打印出来,System.out.println(object.toString());它看起来像是这样的:
[objvar, values, test, object, servar, larms, aggregates, sink, records]
Run Code Online (Sandbox Code Playgroud)
我需要将这些字符串列表动态使用它.能否请你帮忙?
在尝试理解 InfluxDb 的不同概念时,我遇到了这个文档,其中有与 SQL 数据库的术语比较。
InfluxDB 测量类似于 SQL 数据库表。
InfluxDB 标签就像 SQL 数据库中的索引列。
InfluxDB 字段就像 SQL 数据库中未索引的列。
InfluxDB 点类似于 SQL 行。
但是我遇到了其他几个术语,我无法清楚地理解并想知道是否有 SQL 等效项。
系列
铲斗
从我从文档中了解到的
系列是共享保留策略、度量和标记集的数据集合。
这是否意味着系列是数据库表中数据的子集?还是像数据库视图?
我看不到任何解释桶的文档。我猜这是 2.0 版本中的一个新概念
有人可以澄清这两个概念吗?
当我尝试使用内存 h2 数据库和 Jpa 配置 micronaut-data 时,出现以下异常。
我一直在关注文档
我使用 maven 作为构建工具从命令行创建了该项目。我有以下
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-jdbc-tomcat</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-hibernate-jpa</artifactId>
<version>1.0.0.M3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
而且我还添加了这样的注释处理器
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
......
<configuration>
...
<annotationProcessorPaths>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-validation</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>1.0.0.M3</version>
</path>
</annotationProcessorPaths>
</configuration>
.....
</plugin>
Run Code Online (Sandbox Code Playgroud)
我的实体类和存储库类与指南中提到的完全一样。当我尝试使用存储库保存时,出现此异常
18:16:37.787 [pool-1-thread-3] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: No backing RepositoryOperations configured for repository. Check your configuration and try again
io.micronaut.context.exceptions.ConfigurationException: No backing RepositoryOperations configured …Run Code Online (Sandbox Code Playgroud) 似乎 ConditionalOnProperty 仅适用于类路径中的属性,如资源文件夹中的 application.properties。我需要一个最终用户可以通过外部属性打开和关闭的属性。一个例子非常简单:
配置类,读取外部属性。Sys.out 显示它正在正确读取文件。
@Configuration
@EnableAutoConfiguration
@PropertySource("file:/Users/end.user/MyApp/config/MyApp.properties")
public class PropertyConfigurer {
@Value("${featureOne}")
private String featureOne;
@PostConstruct
public void init() {
System.out.println("FeatureOne : " + featureOne);
}
}
Run Code Online (Sandbox Code Playgroud)
要素类,如果通过 ConditionalOnProperty 启用该属性,则该组件类将被放入应用程序上下文中以便能够使用,否则永远不会实例化该组件。
@Component
@ConditionalOnProperty(name="featureOne", havingValue = "true")
public class FeatureOne {
@PostConstruct
public void init() {
System.out.println("Feature initialized");
}
}
Run Code Online (Sandbox Code Playgroud)
正如您可以想象的那样,由于“featureOne”属性在构造此类之后才可用于 spring 上下文,因此我永远不会看到“功能已初始化”。如果有某种方法可以在类实例化时强制来自 @PropertySource 的属性可用于 spring 上下文。还是有其他方式?我也尝试过 @DependsOn 来自 FeatureOne 的 PropertyConfigurer,但有趣的是,这也不起作用。
spring ×7
java ×5
spring-boot ×3
mongodb ×2
arraylist ×1
influxdb ×1
influxdb-2 ×1
jackson ×1
json ×1
micronaut ×1
properties ×1
rest ×1
spring-data ×1
spring-test ×1