以下代码的作用如下:
WeatherWidget.prototype = new Widget;
Run Code Online (Sandbox Code Playgroud)
哪里Widget
是构造函数,我想用新函数扩展Widget'类' WeatherWidget
.
什么是new
关键字在那里做什么以及如果被遗漏会发生什么?
我有一个网络应用程序,web.xml
我在其中添加了HttpSessionEventPublisher
作为监听器.Web应用程序在Jetty 7.x上运行,我们使用的是Spring 3.1.1.
这应该是触发HttpSessionCreatedEvent
和HttpSessionDestroyedEvent
Spring上下文事件监听器.
我有一个@Controller
实现的Bean()ApplicationListener<ApplicationEvent>
.ApplicationEvent
是共同的父类的HttpSessionCreatedEvent
和HttpSessionDestroyedEvent
.当我现在登录到我的Web应用程序或从中退出时,我希望将这些事件触发到该onApplicationEvent(ApplicationEvent event)
方法.我收到了一些其他事件,比如一些请求处理事件,但预期的事件没有显示出来.我已经跟踪了一下应用程序,HttpSessionEventPublisher
肯定会将事件触发到上下文,但是没有接近监听器.我在这里想念什么?
我编写了一个没有嵌入式服务器的小型 spring-boot 应用程序。它旨在从命令行运行并保持运行直到虚拟机收到信号。spring-boot 框架(v2.0)中使应用程序作为服务保持活动的预期方式是什么?我的方法中应该有Thread.currentThread().wait();
最后一个语句吗?run(ApplicationArguments args)
有启用注释吗?
我在这里有一些@ javax.xml.bind.annotation.Xml ...注释类用于RESt Web服务.Jersey是在一个Spring托管的Web容器中设置的,Web服务正在返回格式良好的xml.我们使用maven-enunciate-plugin来记录Web服务并为返回的xml文档创建xsd.我现在想将文档xsd文件用作返回的xml文件中的schemaLocation,以便xml验证不会抱怨缺少定义.如何为此配置XML序列化?
我已经创建了一个Spring @Configuration注释类,我想要将一个ResourceLoader自动装配到它,以便我可以在其中一个@Bean方法中使用它来查找由String给出的文件.当我运行应用程序并初始化上下文时,我得到一个访问自动装配字段的NPE,并且在调试模式下,它显示为空/未设置.我错在期待resourceLoader存在吗?我错误地断言配置bean的自动装配发生在其方法被调用之前?加载此bean的xml配置标记为<context:annotation-config />
@Configuration
public class ClientConfig {
@Autowired
private ResourceLoader resourceLoader;
public @Bean
String configHome() {
return System.getProperty("CONFIG_HOME");
}
public @Bean
PropertiesFactoryBean appProperties() {
String location = "file:" + configHome() + "/conf/webservice.properties";
PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
factoryBean.setLocation(resourceLoader.getResource(location));
return factoryBean;
}
}
Run Code Online (Sandbox Code Playgroud) 我这里有一个尺寸为2156x1728的黑/白png文件,我希望使用AffineTransform旋转90度.生成的图像没有正确的比例.这里有一些示例代码(假设我已成功将png文件加载到BufferedImage中):
public BufferedImage transform(BufferedImage image){
System.out.println("Input width: "+ image.getWidth());
System.out.println("Input height: "+ image.getHeight());
AffineTransform affineTransform = new AffineTransform();
affineTransform.setToQuadrantRotation(1, image.getWidth() / 2, image.getHeight() / 2);
AffineTransformOp opRotated = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR);
BufferedImage transformedImage = opRotated.createCompatibleDestImage(image, image.getColorModel());
System.out.println("Resulting width: "+ transformedImage.getWidth());
System.out.println("Resulting height: "+ transformedImage.getHeight());
transformedImage = opRotated.filter(image, transformedImage);
return transformedImage;
}
Run Code Online (Sandbox Code Playgroud)
输出相应:
输入宽度:2156
输入高度:1728
结果宽度:1942年
结果身高:1942年
旋转如何回归这些完全不相关的尺寸?
考虑我想使用Java 8流API打印文件列表的行.我该怎么写呢?
这不是我的真实情况,只是一种非常简化的形式.
File[] files;
Arrays.stream(files). // what now?
Run Code Online (Sandbox Code Playgroud)
我想过把它映射File
到Stream<String>
但是后来我卡住了.
鉴于这种情况:数据库是在 Hibernate 尚未诞生时创建的,我们在这里谈论真正的遗产。我有从未删除记录的表,只是在行上设置一个活动标志以将条目标记为当前正在使用。查询通常如下所示:
SELECT * from A left join B on A.id = B.a_id and B.active = 1
Run Code Online (Sandbox Code Playgroud)
使用 Java 定义的实体 A 和 B,并且 A 有一个属性
@OneToMany
private Set<B> b;
Run Code Online (Sandbox Code Playgroud)
如何注释属性以添加条件“and B.active=1”?
首选 JPA 解决方案,但如有必要,我们也可以使用休眠注释。
以类似的方式,我们有条目具有活动日期范围的情况,因此我们必须添加类似于
"and B.active_From >= now() and (B.active_to is null or B.active_to < now())"
Run Code Online (Sandbox Code Playgroud) java ×3
spring ×2
autowired ×1
awt ×1
bash ×1
constructor ×1
daemon ×1
hibernate ×1
java-8 ×1
java-stream ×1
javascript ×1
jaxb ×1
jersey ×1
jpa ×1
prototype ×1
session ×1
spring-boot ×1
syntax ×1
variables ×1