Java属性文件绑定到Java接口

使用GWT你有这样的东西: public interface LoginConstants extends Constants { @DefaultStringValue(“Wellcome to my super app”) @Key(“appDescription”) String appDescription(); @DefaultStringValue(“Ok”) @Key(“okButtonLabel”) String okButtonLabel(); } 然后你可以在你的类中使用GWT.create(LoginConstant.class),这样接口就会被动态实现支持,当我调用loginConstants.appDescription()时,使用@Key注释返回属性文件中包含的值引用属性文件中的键。 如果属性文件遗漏了该属性,则返回de @DefaultStringValue。 这用于国际化,但也可能用于配置。 但是对于GWT,这意味着要在客户端使用(即转换为JavaScript),对于i18n,而不是用于配置。 但是,我发现这个想法对于配置处理也非常方便。 我想知道是否有人知道在服务器端执行类似操作的框架,而不必将代码绑定到GWT。 即。 如果有任何库实现了专门为配置处理而设计的这种逻辑。 我不知道这样的事情。 参考GWT中的function: https : //developers.google.com/web-toolkit/doc/latest/DevGuideI18nConstants

Javagenerics:声明generics类型的映射值

我是仿制药的新手。 像Map一样 private static Map map; 和像这样的方法 public T getObject(final Class myClass) { return (T)map.get(myClass); } 如何更改map声明,以便在从方法返回时不必进行强制转换?

Tomcat活动线程堆积并停止服务器

我们的生产服务器(apache-tomcat-7.0.6)遇到了这个问题,它使用MySQL作为DB运行Spring-JPA-Hibernate应用程序。 在此问题期间,服务器变得缓慢,并且在一分钟内它变得没有响应,活动的tomcat线程数量最多可以达到200(我们使用javamelody来观察这些事情)。 日志看起来像: 2012-04-07 07:53:48,058 DEBUG AuthenticationHandler:(“http-bio-7006”-exec-304):35 – Authentication handler : ~ 2012-04-07 07:53:48,059 DEBUG AuthenticationHandler:(“http-bio-7006”-exec-304):45 – Service Id : 1333765428059-/xxx-framework-service/platform/items/search/ 2012-04-07 07:53:48,060 DEBUG DefaultListableBeanFactory:(“http-bio-7006”-exec-304):242 – Returning cached instance of singleton bean ‘transactionManager’ 2012-04-07 07:53:48,060 DEBUG JpaTransactionManager:(“http-bio-7006″-exec-304):365 – Creating new transaction with name [com.xxx.framework.manager.ItemManager.search]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ” 2012-04-07 07:53:48,060 DEBUG JpaTransactionManager:(“http-bio-7006”-exec-304):323 – Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@6aee43a9] […]

Java – 来自构造函数的setter

package cen.col.course.demo; import java.io.Serializable; public class Course implements Serializable { private static final long serialVersionUID = 1L; protected String code; protected String title; protected Professor professor; public Course( String code) throws InvalidDataException { super(); setCode(code); } public Course(String code, String title ) throws InvalidDataException { this(code); setTitle(title); } public Course(String code, String title, Professor professor) […]

在java中执行linux命令并将输出显示到html表

我有jsp代码df -h在网站上显示磁盘信息。 如何用表格显示输出到html? 代码下方: String[] disk; String line; String process; Process p; BufferedReader input; p = Runtime.getRuntime().exec(“df -h”); input = new BufferedReader(new InputStreamReader(p.getInputStream())); input.readLine(); disk = input.readLine().split(“\\s+”); <% Disk Size Used Avail Use% Mount while ((line = input.readLine()) != null) { %> 在Linux上我执行“ df -h ”它显示如下: [root@svr1 apache-tomcat-7.0.32]# df -h Filesystem Size Used Avail Use% […]

setPreferredSize的副作用是什么?

我有包含多个面板的窗口。 我无法访问窗口代码。 (我只能修改面板的代码。) 我从面板中删除了一些组件。 窗户缩小了它的尺寸。 但窗口太小,无法正确显示所有内容。 我添加了行setPreferredSize(getPreferredSize()); 。 现在窗口大小合适。 setPreferredSize的副作用是什么? 编辑:使用BorderLayout。 哪个应该忽略getXXXSize()。 我的小组在CENTER。 不适合屏幕的面板位于NORTH。

如何使会话数据可序列化

以前我们已经实现了粘性会话。 这是我们环境的链接: apache中的Sticky Session不起作用 我们的下一个任务是实现会话复制。 我们目前正在使用tomcat示例cart.jsp来演示此行为。 据说所有session属性都必须实现java.io.serializable。 你有任何关于在哪里实施它的提示吗? 我们正在密切关注本教程。 tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

在jar文件中加载图像

我正在尝试从可执行的JAR文件加载图像。 我已经按照这里的信息,然后是这里的信息。 这是检索图像的function: public static ImageIcon loadImage(String fileName, Object o) { BufferedImage buff = null; try { buff = ImageIO.read(o.getClass().getResource(fileName)); // Also tried getResourceAsStream } catch (IOException e) { e.printStackTrace(); return null; } if (buff == null) { System.out.println(“Image Null”); return null; } return new ImageIcon(buff); } 这就是它被称为的方式: logo = FileConverter.loadImage(“/pictures/Logo1.png”, this); JFrame.setIconImage(logo.getImage()); 这是一个简单的对象。 我也没有得到NullPointerException,除非它被UI掩盖。 […]

Geocoder.isPresent()未定义类型Geocoder

我的Android和Java技能不是很热…… 在Geocoder的developer.android.com页面中,它说: 如果平台中没有后端服务,则Geocoder查询方法将返回空列表。 使用isPresent()方法确定是否存在Geocoder实现。 但是,当我尝试打电话时,例如: if (Geocoder.isPresent()) {… Eclipse告诉我 对于Geocoder类型,方法isPresent()未定义 我如何“使用isPresent()方法”?

自定义Jerseyerror handling,如何在客户端捕获响应?

我正在尝试在我的webservice上进行一些自定义error handling。 在我的webservice中,我创建了一个自定义的Exception类,扩展了WebApplicationException,如JAX-RS / Jersey中所描述的, 如何自定义error handling? : public class InternalServerErrorException extends WebApplicationException { public InternalServerErrorException(String message) { super(Response.status(Response.Status.INTERNAL_SERVER_ERROR) .header(“errorMessage”, message).type(MediaType.TEXT_PLAIN).build()); System.out.println(message); } } 为了测试,我有一个简单的国家/地区服务,它提供了一个国家列表。 我确保测试抛出InternalServerErrorException会发生错误: @GET @Override @Path(“countries”) @Produces({“application/xml”}) public List findAll() { try { int i = Integer.parseInt(“moo”); //<– generate error List countries = super.findAll(); return countries; } catch (Exception ex) { throw […]