Tag: 属性

Java System.getProperty(“user.timezone”)不起作用

当我通过java -Duser.timezone=”UTC”启动java程序java -Duser.timezone=”UTC” , System.out.println( System.getProperty( “user.timezone” ) ); System.out.println( new Date() ); // prints time in UTC 打印UTC时间,但是当我在代码中设置如下: System.setProperty( “user.timezone”, “UTC” ); System.out.println( System.getProperty( “user.timezone” ) ); // prints ‘UTC’ System.out.println( new Date() ); // prints time in local zone, not in UTC 不以UTC格式打印时间。 我需要在代码中设置时间。 不寻找乔达 环境:JDK 1.6 / Windows XP 请帮忙。 非常感谢!

使用Properties动态读取/添加conf文件参数的值

我的conf文件中有如下消息。 text.message = Richard必须在01/06/2012 / 1days 。 所有突出显示的字段都是可变的 我想阅读这个text.me字符串并使用Properties插入我的java中的值。 我知道如何使用Prop读取整个字符串,但不知道如何读取如上所述的字符串。 text.message = #name#必须在text.message = #name# #/#days#中转到#place#。 如何使用Properties从conf中读取上述字符串并动态插入数据? 它可以是字符串中的日期或天数。 我如何在这些参数之间打开和关闭? 谢谢你。

使用@PropertySource进行Spring属性配置

在下面的Spring配置类中,我通过@PropertySource加载app.properties文件,并使用属性文件中的配置构建2个不同的DBCP数据源。 虽然一切正常,但我不喜欢为带有注释的每个配置属性声明一个变量以构造数据源。 我试着像这样自动assembly环境类 @Autowired Environment env; 但是,当env.getProperty()返回null时。 有一个更好的方法吗? @Configuration @PropertySource(“classpath:app.properties”) public class DAOConfig { @Value( “${txn.dbhost}” ) private String txnDbHost; @Value( “${txn.dbport}” ) private Integer txnDbPort; @Value( “${txn.dbservice}” ) private String txnDbService; @Value( “${txn.dbuser}” ) private String txnDbUser; @Value( “${txn.dbpwd}” ) private String txnDbPwd; @Value( “${rpt.dbhost}” ) private String rptDbHost; @Value( “${rpt.dbport}” ) private Integer […]

使用Google Guice注入java属性

我想使用谷歌guice在我的应用程序的所有类中提供属性。 我定义了一个模块,它加载和绑定属性文件Test.properties 。 Property1=TEST Property2=25 包com.test; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Properties; import com.google.inject.AbstractModule; import com.google.inject.name.Names; public class TestConfiguration extends AbstractModule { @Override protected void configure() { Properties properties = new Properties(); try { properties.load(new FileReader(“Test.properties”)); Names.bindProperties(binder(), properties); } catch (FileNotFoundException e) { System.out.println(“The configuration file Test.properties can not be found”); } catch […]

JavaBeans的替代品?

我讨厌JavaBeans模式的激情像一千个太阳的火焰一样燃烧。 为什么? 详细 。 这是2009年。我不应该为房产写7 LOC。 如果他们有事件听众,那么请抓住你的帽子。 没有类型安全的参考 。 没有类型安全的方法来引用属性。 Java的全部意义在于它是类型安全的,它最流行的模式并不是所有类型都安全的。 我想要的是: class Customer { public Property name = new Property(); } 我主要是一名Web开发人员,因此需要JPA和Wicket支持。 帮助我离开javabean火车!

忽略名称空间的JAXB解组将元素属性转换为null

我正在尝试使用JAXB将xml文件解组为对象,但遇到了一些困难。 实际项目在xml文件中有几千行,所以我在较小的范围内重现了错误,如下所示: XML文件: 用于生成JAXB类的XSD文件 代码段1: final JAXBContext context = JAXBContext.newInstance(CatalogueType.class); um = context.createUnmarshaller(); CatalogueType ct = (CatalogueType)um.unmarshal(new File(“file output address”)); 这引发了错误: javax.xml.bind.UnmarshalException: unexpected element (uri:”x-schema:TamsDataSchema.xml”, local:”catalogue”). Expected elements are at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:247) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:242) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1049) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459) at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:148) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at […]

在xml中定义Spring @PropertySource并在Environment中使用它

在Spring JavaConfig中,我可以定义属性源并注入到Environment中 @PropertySource(“classpath:application.properties”) @Inject private Environment environment; 如果在xml中我该怎么做? 我使用context:property-placeholder,并在JavaConfig类@ImportResource上导入xml。 但我无法使用environment.getProperty(“xx”)检索属性文件中定义的属性

如何使用BeanUtils.copyProperties?

我试图将属性从一个bean复制到另一个bean。 这是两个bean的签名: SearchContent : public class SearchContent implements Serializable { private static final long serialVersionUID = -4500094586165758427L; private Integer id; private String docName; private String docType; private String docTitle; private String docAuthor; private String securityGroup; private String docAccount; private Integer revLabel; private String profile; private LabelValueBean workflowStage; private Date createDate; private Date inDate; private String […]

在静态初始化程序块中加载java属性

我有一个静态util类,它对位敏感数据进行一些字符串操作。 在使用这个类之前,我需要使用我喜欢存储在.properties文件中的值(例如usernames / password)来初始化某些静态变量。 我不太熟悉.properties文件的加载如何在Java中工作,特别是在* Spring DI *容器之外。 任何人都可以帮助我了解如何做到这一点? 谢谢! 另外: .properties文件的精确位置未知,但它将在classpath上。 像classpath:/my/folder/name/myproperties.propeties一样classpath:/my/folder/name/myproperties.propeties

将.properties文件放在Eclipse项目中的位置?

我有一个非常简单的属性文件测试我试图工作:(以下是TestProperties.java) package com.example.test; import java.util.ResourceBundle; public class TestProperties { public static void main(String[] args) { ResourceBundle myResources = ResourceBundle.getBundle(“TestProperties”); for (String s : myResources.keySet()) { System.out.println(s); } } } 和TestProperties.properties在同一目录中: something=this is something something.else=this is something else 我也保存为TestProperties_en_US.properties 当我从Eclipse运行TestProperties.java时,它找不到属性文件: java.util.MissingResourceException: Can’t find bundle for base name TestProperties, locale en_US 难道我做错了什么?