使用GroupLayout在Java中构建表单的最简单方法是什么?对于表单,我的意思是具有前面带有标签的文本字段.像这样的东西:

我正在从Google Collections 0.9升级到1.0.它似乎Sets.newConcurrentHashSet()已不再可用.我在以下构造中使用它:
public static <K, V> Multimap<K, V> newConcurrentMultimap()
{
return Multimaps.newMultimap( new ConcurrentHashMap<K, Collection<V>>(), new Supplier>()
{
@Override
public Collection<V> get()
{
return Sets.<V>newConcurrentHashSet();
}
} );
}
什么是Sets.newConcurrentHashSet()的最佳替代品?
编辑:这个构造的原因是有一个可以安全地从多个线程读取和写入的多图.它用于一个主要阅读的场景(并将被阅读很多).
问候,
维姆
我刚刚开始使用Netty(使用4.0.15.Final).我想从现有的硬件设备读取消息,该设备可以使用专有协议.我已经实现了如下:
public class Xml2StreamProtocolDecoder extends ByteToMessageDecoder
{
private static final int LENGTH_OF_START_SENTINEL_IN_BYTES = 1;
private static final int LENGTH_OF_END_SENTINEL_IN_BYTES = 1;
private static final int LENGTH_OF_LENGTH_FIELD_IN_BYTES = 4;
@Override
protected void decode( ChannelHandlerContext ctx, ByteBuf in, List<Object> out ) throws Exception
{
if( in.readableBytes() > LENGTH_OF_START_SENTINEL_IN_BYTES + LENGTH_OF_LENGTH_FIELD_IN_BYTES)
{
short startSentinel = in.readUnsignedByte();
if (startSentinel != 0x01)
{
throw new CorruptedFrameException( "startsentinel not as expected, was " + startSentinel + " while we expect 0x01" );
}
int messageLength = …Run Code Online (Sandbox Code Playgroud) 假设您有以下实体:
@Entity
public class Game {
@Id
@GeneratedValue
private Integer id;
private String name;
private Calendar startTime;
private int durationInSeconds;
public GameStatus getStatus() {
if( startTime.after(Calendar.getInstance()))
{
return GameStatus.SCHEDULED;
} else {
Calendar endTime = Calendar.getInstance();
endTime.setTime(startTime.getTime());
endTime.roll(Calendar.SECOND, durationInSeconds);
if( endTime.after(Calendar.getInstance())) {
return GameStatus.OPEN_FOR_PLAY;
}
else {
return GameStatus.FINISHED;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我GameRepository是a PagingAndSortingRepository,我如何获得一个结果页面,按status属性排序?
我目前得到:
java.lang.IllegalArgumentException: Unable to locate Attribute with the the
given name [status] on this ManagedType [org.test.model.Game]
Run Code Online (Sandbox Code Playgroud)
我可以理解,因为status确实没有JPA属性.有没有解决的办法?
(我在下面使用Hibernate,所以任何特定的Hibernate都可以)
我的实体(使用 Spring Boot 与 Spring Data JPA 和 Hibernate)都是从AbstractEntity我定义的类扩展的。这个类以这样的方式实现equals(),hashcode()子类不再需要处理这个问题。
SonarQube 现在将报告以下违规行为:
添加字段的子类应该覆盖“equals”
对于每个子类。
我可以通过添加@SuppressWarnings("squid:S2160")每个子类来抑制这种情况。但我想知道是否有一种方法可以向 SonarQube 声明:如果一个类是其子类,则不应触发此规则,AbstractEntity因此我不需要在每个子类中重复抑制警告。
我正在尝试在我的 Spring Java 配置中添加一个 BeanPostProcessor。它似乎有效但仅适用于通过组件扫描创建的 bean (@Configuration, @RestController, ..)
我在 Java 配置中创建的 Bean 不是。
例如
@Configuration
public class MyConfiguration
{
@Bean
public MyBean myBean()
{
return new MyBean();
}
@Bean
public static MyBPP myBeanPostProcessor()
{
return new MyBPP();
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我确实将 BeanPostProcessor 的方法声明为静态(参见http://forum.spring.io/forum/spring-projects/container/123899-beanpostprocessor-with-bean-annotation-not-working)。
因此创建了一个 MyBean 实例,但 BeanPostProcessor 永远不会处理它。
我试图让我的应用程序在MySQL(用于生产)和H2(用于开发/测试)上运行.我的(Flyway)脚本现在几乎完全相同,除了需要为MySQL声明'LONGTEXT'的列.如果我也将它用于H2(在MySQL兼容模式下运行),我得到:
Wrong column type in public.public.customer_license for column license.
Found: clob, expected: varchar(65535)
Run Code Online (Sandbox Code Playgroud)
我的实体的Java代码:
@Column(name = "license", length = 65535)
private String m_license;
Run Code Online (Sandbox Code Playgroud)
如果我将列声明更改为VARCHAR(65535),那么它适用于H2,但不适用于MySQL:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Column length too big for column 'license'
(max = 21845); use BLOB or TEXT instead
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它适用于两者?
我有一个使用@ConfigurationProperties组件的 Spring Boot 2.2.6 应用程序,如下所示:
@Component
@ConfigurationProperties("myapplication")
public class MyApplicationSettings {
private LocalTime startOfDay;
// getter and setters here
}
Run Code Online (Sandbox Code Playgroud)
我的集成测试突然开始在 Jenkins 上失败,但在本地运行良好。异常显示如下:
Description:
Failed to bind properties under 'myapplication.start-of-day' to java.time.LocalTime:
Property: myapplication.start-of-day
Value: 06:00
Origin: class path resource [application-integration-test.properties]:29:62
Reason: failed to convert java.lang.String to java.time.LocalTime
Action:
Update your application's configuration
Run Code Online (Sandbox Code Playgroud)
完整的异常跟踪的根本原因是:
Caused by: java.time.format.DateTimeParseException: Text '06:00' could not be parsed at index 5
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
at java.base/java.time.LocalTime.parse(LocalTime.java:463)
at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(TemporalAccessorParser.java:72)
at org.springframework.format.datetime.standard.TemporalAccessorParser.parse(TemporalAccessorParser.java:46)
at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:217) …Run Code Online (Sandbox Code Playgroud) 我需要使用 ffmpeg 从指向图像的 HTTP url 创建电影/流。该图像每秒更新 1 次。
我已经知道如何使用 ffmpeg 命令行从 MPEG-4 转换为 flv,但现在我需要从这个更新的静态图像开始。例如,我希望 ffmpeg 每秒“获取”网址 1 次。
问候,
维姆
我正在使用 Spring Boot 2.2.5 和 Spring Security 5.2.2 usingspring-security-oauth2-resource-server和spring-security-oauth2-jose依赖项。
在我的控制器方法中,我有这个工作:
@GetMapping
public ResponseEntity<?> doSomething(@AuthenticationPrincipal JwtAuthenticationToken principal) {
User user = getUser(principal);
...
}
Run Code Online (Sandbox Code Playgroud)
将principal被注入并包含在Azure上的用户(我使用Azure的AD B2C)的ID。
在每个方法中我需要做的第一件事是User使用这个User从我的userServiceSpring bean中检索 的私有方法来获取我自己的对象:
private User getUser(JwtAuthenticationToken principal) {
AuthorizationServerUserId authorizationServerUserId = AuthorizationServerUserId.fromPrincipal(principal);
return userService.findByAuthorizationServerUserId(authorizationServerUserId)
.orElseThrow(() -> UserNotFoundException.forAuthorizationServerUserId(authorizationServerUserId));
}
Run Code Online (Sandbox Code Playgroud)
如何配置 Spring (Boot) 以使其有效:
@GetMapping
public ResponseEntity<?> doSomething(@AuthenticationPrincipal User user) {
}
Run Code Online (Sandbox Code Playgroud)
目前安全配置是这样完成的:
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter …Run Code Online (Sandbox Code Playgroud) java ×9
spring ×3
spring-boot ×3
ffmpeg ×1
grouplayout ×1
guava ×1
h2 ×1
jpa ×1
mysql ×1
netty ×1
sonarqube ×1
spring-data ×1
swing ×1