我想@ServiceActivator
在Java 8默认接口方法上使用注释.此默认方法将根据业务规则委托此接口的另一个方法.
public interface MyServiceInterface {
@ServiceActivator
public default void onMessageReceived(MyPayload payload) {
if(payload.getAction() == MyServiceAction.MY_METHOD) {
...
myMethod(...);
}
}
public void myMethod(...);
}
Run Code Online (Sandbox Code Playgroud)
然后,此接口由Spring @Service
类实现:
@Service
public class MyService implements MyServiceInterface {
public void myMethod(...) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
执行代码时,这不起作用!
我只能让它@ServiceActivator
从默认方法中删除注释,并覆盖我的@Service
类中的默认方法并委托给super方法:
@Service
public class MyWorkingService implements MyServiceInterface {
@ServiceActivator
@Override
public void onMessageReceived(MyPayload payload) {
MyServiceInterface.super.onMessageReceived(payload);
}
public void myMethod(...) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
覆盖默认方法会忽略默认方法的用途.
是否有其他方式以干净的方式实现此方案?
在Debian上运行的MySQL数据库(版本5.5.41-0 + wheezy1-log).
hotels
带有列name VARCHAR(128)
和引擎的表是InnoDB.
CREATE TABLE `hotels` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT
`name` varchar(128) NOT NULL DEFAULT '' COMMENT 'Hotel Name',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)
此表中有两条记录:
1 BEST WESTERN PREMIER LE CARRE FOLIES OPERA
2 BEST WESTERN PREMIER LE CARRÉ FOLIES OPÉRA
Run Code Online (Sandbox Code Playgroud)
执行时select DISTINCT name FROM hotels
,查询只返回1条记录,而预计会返回2条记录.
DBMS在E和É之间似乎没有区别.
如何更改表设置以获得预期结果?
考虑这个课程:
package be.duo.test;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.execute();
}
private void execute() {
for(int i = 0; i < 10; i++) {
System.out.println("" + method());
}
}
private int method() {
return (Math.random() > 0.5d) ? 1 : null;
}
}
Run Code Online (Sandbox Code Playgroud)
method()具有返回类型int
,它是一种基本类型.
考虑return语句中使用的三元运算符:
[ERROR] error: incompatible types: bad type in conditional expression
[ERROR] <null> cannot be converted to int
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释为什么它表现不同吗?
java compiler-errors nullpointerexception primitive-types maven
在我们的 Spring Web 应用程序中,我们正在从基于 XML 的配置转向基于注释的配置。
我被这个 XML 定义的计划任务所困扰
<task:scheduled-tasks scheduler="cacheScheduler">
<task:scheduled ref="currencyExchangeRateTask" method="cacheCurrencyExchangeRates" cron="0 0 8,20 * * *" />
</task:scheduled-tasks>
Run Code Online (Sandbox Code Playgroud)
我们的网络应用程序中有多个调度程序。而这个任务需要在 id 的调度器上执行cacheScheduler
。
我现在有以下注释
@Scheduled(cron = "0 0 8,20 * * *")
public void cacheCurrencyExchangeRates() {
...
}
Run Code Online (Sandbox Code Playgroud)
这是在默认调度程序上执行的。
如果没有 XML 配置,如何解决这个问题?
考虑一个@RestController
带有@GetMapping
映射到的 Spring MVC/v1/**
来处理所有子路径。
@RestController
public class MyController {
@GetMapping(value = "/v1/**", produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView handle(String fullPathInMethodArg) {
...
String fullPathInLocalVar = ...;
...
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能检索完整路径?
理想情况下,我想找回它作为方法的参数:String fullPathInMethodArg
。
另外,我想找回它作为一个局部变量:String fullPathInLocalVar
。