Spring Boot使用@ConfigurationProperties注释为我们提供了类型化的配置对象.其中一个优点是在使用Spring Boot注释处理器时可以在IDE中免费获取属性名称.另一个是:验证.
现在,我想根据属性的值来制作一个bean.实际上,我有两个接口的实现,这个属性告诉我应该使用哪一个.我可以像这样实现它:
ImplementationA.java
@Component
@ConditionalOnProperty(name = "foo.bar", havingValue = "a")
public class ImplementationA implements SomeInterface { ... }
Run Code Online (Sandbox Code Playgroud)
ImplementationB.java
@Component
@ConditionalOnProperty(name = "foo.bar", havingValue = "b")
public class ImplementationB implements SomeInterface { ... }
Run Code Online (Sandbox Code Playgroud)
application.yml
foo:
bar: "a"
Run Code Online (Sandbox Code Playgroud)
但是,我会失去打字配置的优势.所以我想在一个@ConfigurationProperties对象中声明这个属性:
FooProperties.java
@ConfigurationProperties(prefix = "foo")
public class FooProperties {
private String bar;
public String getBar() { ... }
public void setBar(String bar) { ... }
}
Run Code Online (Sandbox Code Playgroud)
这仍然可以工作,但是当我bar在这个类中声明一个默认值时,它显然不会被拾取,@ConditionalOnProperty因为这个注释Environment直接对应(如设计).所以也许最好不要混合这些概念.
是否有办法根据@ConfigurationProperties …
我正在尝试通过其REST API https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#EventoperationsCreateevents将一些事件导出到Office 365中的日历。
我将设置IsAllDay为true,并将开始时间和结束时间设置为UTC。
有效负载如下所示:
{
"Body": {
"Content": "Agenda",
"ContentType": "HTML"
},
"End": "2015-02-01T00:00:00Z",
"ShowAs": "Busy",
"Start": "2015-01-30T00:00:00Z",
"ChangeKey": "X2+akAeClEa0OJ8r6nC5QgABW30vaQ==",
"Location": {
"DisplayName": "Vesterbrogade"
},
"Subject": "Updated title",
"IsAllDay": true
}
Run Code Online (Sandbox Code Playgroud)
看起来不错,如果我再次获取该事件,则有效负载会按设置返回。但是,当我访问outlook.office365.com时,该事件现在跨越2天,而不是预期的1天。但是,持续时间显示为1天。在Outlook中取消单击“全天”即可发现问题。由于我处于中欧时间,所以我比UTC早一小时。开始显示为2015-01-30 01:00,结束显示为2015-02-01 00:59。因此,在幕后看来,它似乎并没有存储为我所在时区的全天事件。
当您使用f.ex. EWS,您通常设置会议的时区,但是似乎无法实现。
我尝试提供时区信息的开始和结束,但是我得到400告诉我必须使用UTC进行提供。据我所知,我无能为力,希望微软会解决此问题。还是我错过了什么?
编辑:该事件实际上在Mac的Outlook中正确显示,所以也许这只是OWA中的一个问题,位于Outlook.office365.com。
我正在尝试将 Spring Data JDBC 用于我的 PostgreSQL 数据库。我定义了以下bean
@Data
class Report {
@Id
private Long id;
private String name;
private Set<Dimension> dimensions;
}
@Data
class Dimension {
private String name;
private Long[] filterIds;
}
Run Code Online (Sandbox Code Playgroud)
以及相应的DDL
CREATE TABLE report (
id bigserial PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE dimension (
id bigserial PRIMARY KEY ,
report bigint,
name text,
filter_ids bigint[],
FOREIGN KEY (report) REFERENCES report(id) ON DELETE CASCADE ON UPDATE CASCADE
);
Run Code Online (Sandbox Code Playgroud)
然后我尝试插入报告
final Dimension dimension = new …Run Code Online (Sandbox Code Playgroud)