我一直在寻找一段时间没有运气.我没有使用Spring MVC,但仍想使用它@javax.validation.Valid来启用方法参数的验证.举个例子
public class EventServiceImpl implements IEventService {
@Override
public void invite(@Valid Event event, @Valid User user) { ... }
}
Run Code Online (Sandbox Code Playgroud)
使用MVC,这对带@Controller注释的bean的启用很简单<mvc:annotation-driven/>(参见5.7.4.3配置JSR-303验证器供Spring MVC使用).
使用AOP应该是非常简单的.不过,我怀疑有一些标准的方法可以做到这一点.因此,问题是:对于非MVC应用程序和非控制器bean,是否存在类似的事情,以便为带注释的bean启用输入验证?
我有一个包含多个项目的SVN存储库,例如
目前,我已经配置了3个项目,全部使用共享的VCS root/molindo.
默认情况下,每次提交都会触发所有3个项目的构建(尽管trunk/foo不关心trunk/bar或trunk/baz的更改).正如我所见,可以配置VCS触发器(例如+:/ trunk/foo/**用于项目foo).虽然这适用于构建触发,但它仍然显示其他项目的待定更改.
那么我现在有什么选择呢.我能想到
两种选择都不是最理想的.第一个因为它很丑,第二个因为它很麻烦.还有其他我不知道的选择吗?或者是否有另一个(首选)从共享SVN存储库构建多个项目?
是置备IOPS的硬性限制?IO 峰值是否会超过预配置的 IOPS 数量?
我无法轻易找到关于这个问题的明确答案。虽然我几乎认为它是作为硬限制强制执行的,但文档并不是很确定。
我目前正在尝试使用OSGI,并决定选择一个稍微不典型的OSGI用例.我想在命令行应用程序中使用它.我想要一个带有main(..)一些标志和参数的方法,做一些事情并再次关闭.我不想要的是启动Apache Karaf(或类似的)并在OSGI控制台中运行命令(这可能成为一个可选功能).
为什么OSGI首先用于命令行应用程序?该应用程序应该使用相同库的不同版本(即弹性搜索).而且仅仅因为它当然是坏事.
我应该在捆绑中还是在外面消费服务?如何做到这一点?可能会出现什么问题?
我目前正在研究一个简单的编程问题,可能很有趣的优化 - 至少对于那些认为编程是艺术的人来说:)所以这就是:
如何在保持自然秩序的同时最好地表现长弦乐队?
此外,String表示应匹配^[A-Za-z0-9]+$.(我在这里不是太严格,但是避免使用控制字符或任何可能导致令人头疼的编码,在XML中是非法的,有换行符或类似的字符肯定会导致问题)
这是一个JUnit测试用例:
@Test
public void longConversion() {
final long[] longs = { Long.MIN_VALUE, Long.MAX_VALUE, -5664572164553633853L,
-8089688774612278460L, 7275969614015446693L, 6698053890185294393L,
734107703014507538L, -350843201400906614L, -4760869192643699168L,
-2113787362183747885L, -5933876587372268970L, -7214749093842310327L, };
// keep it reproducible
//Collections.shuffle(Arrays.asList(longs));
final String[] strings = new String[longs.length];
for (int i = 0; i < longs.length; i++) {
strings[i] = Converter.convertLong(longs[i]);
}
// Note: Comparator is not an option
Arrays.sort(longs);
Arrays.sort(strings);
final Pattern allowed = Pattern.compile("^[A-Za-z0-9]+$");
for (int i = 0; i < longs.length; i++) { …Run Code Online (Sandbox Code Playgroud) 是否可以编写一个HQL查询,该查询根据每个类层次结构映射的表的鉴别值对结果进行分组?例如
"select discriminator d, count(*) c from Foo group by discriminator"
Run Code Online (Sandbox Code Playgroud)
像一个映射
<hibernate-mapping>
<class abstract="true" name="Foo">
<!-- SNIP -->
<subclass name="Bar" discriminator-value="BAR">
<!-- SNIP -->
</subclass>
<subclass name="Baz" discriminator-value="BAZ">
<!-- SNIP -->
</subclass>
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
和一个可能的结果
+-----+---+
| d | c |
+-----+---+
| BAR | 3 |
| BAZ | 4 |
+-----+---|
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找的是discriminator我的HQL查询中的有效替换.有什么东西或者我必须去原始SQL吗?
我想使用一个PropertySourceLocator必须在bootstrap期间注册的假装客户端.我有以下内容spring.factories:
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
test.PropertiesConfiguration
Run Code Online (Sandbox Code Playgroud)
同
@Configuration
@EnableFeignClients
public class PropertiesConfiguration {
@Bean
public PropertySourceLocator propertySourceLocator() {
return new MyPropertySourceLocator();
}
}
Run Code Online (Sandbox Code Playgroud)
假装客户端自动装入MyPropertySourceLocator.但是,虽然同一个客户端在常规bean中工作,但它在这里不起作用.所有请求都因此异常而失败:
feign.codec.DecodeException: No qualifying bean of type [org.springframework.boot.autoconfigure.web.HttpMessageConverters] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:173)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:141)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:96)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:92)
at com.sun.proxy.$Proxy23.get(Unknown Source)
at test.MyPropertySourceLocator$1.getProperty(MyPropertySourceLocator.java:32)
at org.springframework.core.env.CompositePropertySource.getProperty(CompositePropertySource.java:59)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:60)
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:511)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:135)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$1.getProperty(PropertySourcesPlaceholderConfigurer.java:132)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:84) …Run Code Online (Sandbox Code Playgroud) 在这里,它说:
这为MountainBike提供了与Bicycle相同的所有字段和方法,但允许其代码专注于使其独特的功能.这使您的子类代码易于阅读.但是,您必须注意正确记录每个超类定义的状态和行为,因为该代码不会出现在每个子类的源文件中.
但是在我的代码中,继承不能正常工作,可能是由于我的代码存在缺陷?
package java1;
class bicycle {
int speed = 0;
int gear = 1;
void accelerate(int incr) {
speed = speed + incr;
}
void decelerate(int incr) {
speed = speed - incr;
}
void changeGear(int val) {
gear = val;
}
void printInfo() {
System.out.println("Speed: " + speed + " Gear: " + gear);
}
}
class mountainbike extends bicycle {
int speed = 10;
}
public class Main {
public static void main(String[] args) { …Run Code Online (Sandbox Code Playgroud) 在我的用例中,我正在尝试同步两个Elasticsearch索引.由于版本控制,这非常简单.但是,在我这样做的时候,我想随时继续写作.
好的,所以我想按时间顺序执行的步骤:
第5步是我目前正在考虑的步骤.我必须确保写入c2的更改不会被来自c1的数据覆盖.使用版本控制对于写入来说相当简单,因为索引操作将失败(VersionConflictEngineException).假设以下情况:
我知道elasticsearch会将已删除的文档保留一段时间:
# index document 1:4
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"ok":true,"_index":"test","_type":"test","_id":"1","_version":4}
# delete document 1:6
$ curl -XDELETE 'http://localhost:9200/test/test/1?version=6&version_type=external'
{"ok":true,"found":true,"_index":"test","_type":"test","_id":"1","_version":6}
# index document 1:4 (ERROR!)
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"error":"VersionConflictEngineException[[test][2] [test][1]: version conflict, current [6], provided [4]]","status":409}
# wait some time
# index document 1:4 (SUCCESS!)
$ curl -XPUT 'http://localhost:9200/test/test/1?version=4&version_type=external' -d '{"message": "test"}'
{"ok":true,"_index":"test","_type":"test","_id":"1","_version":4}
Run Code Online (Sandbox Code Playgroud)
问题显然是"等待一段时间"的一部分.我将不得不依赖已删除的文件一段时间.因此,我需要通过在运行#5时禁止删除任何已删除文档来控制此时间.你会怎么做?
交叉到Elasticsearch小组(以及此相关问题 …
java ×5
algorithm ×1
amazon-ebs ×1
amazon-rds ×1
aop ×1
class ×1
hibernate ×1
inheritance ×1
osgi ×1
sorting ×1
spring ×1
spring-cloud ×1
svn ×1
teamcity ×1