Tag: 属性

Spring Boot:从数据库中检索配置

任何人都可以为我提供一些指导,帮助我实现这一目标。 我想扩展Spring Boot Externalized Configuration,以便我有一个方法可以在我的应用程序的任何地方调用。 此方法将使用键检索属性值。 此方法将首先询问数据库表,如果找不到指定的键,则它将回退到1中描述的PropertySource顺序。 所以我有一个类似的服务: @Service public class ConfigurationService { private final ConfigurationRepository configurationRepository; @Autowired public ConfigurationService(ConfigurationRepository configurationRepository) { this.configurationRepository = configurationRepository; } public String getValue(String key) { Configuration configuration = configurationRepository.findOne(key); // Add something here to get the property from application.properties if the key does not exist in the db return […]

javax.el.PropertyNotWritableException:/index.xhtml @ 29,118 value =“”:集合操作的非法语法

我想创建一个带有本地化选项的登录屏幕来翻译名称,当我从默认英语更改为阿拉伯语时,它会崩溃 这是faces.config.xml en ar mypack.enar msg ManagedBean import java.io.Serializable; import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.faces.event.ValueChangeEvent; /** * * @author body */ @ManagedBean(name = “localize”) @RequestScoped public class LocalizeMBean implements Serializable { /** * @return the countries */ public static Map getCountries() { return countries; } /** * […]

Spring:PropertyPlaceholderConfigurer找不到属性文件

我使用PropertyPlaceholderConfigurer对Spring有一个奇怪的问题。 我的一个豆子设计如下: classpath:jdbc.properties 问题是spring永远不会找到jdbc.properties( FileNotFoundException )。 该文件位于bundle classpath中的名为“resources”的文件夹中(我在OSGi项目中工作)。 我几乎尝试了所有组合(“jdbc.properties”,“/ jdbc.properties”,“classpath:jdbc.properties”,“classpath:/jdbc.properties”,“/ resources / jdbc.properties”等等… )但它永远不会奏效。 有关信息,如果在某些时候,我做的事情如下: URL u = someClassLoader.getResource(“jdbc.properties”); 它确实工作没有任何问题,并找到该文件。 实际上我完全无法理解spring的错误是什么。 如果您有任何想法可以帮助我,请提前感谢。 我在spring不是很有经验,所以我可能在某处犯了一个错误。 [编辑] 实际上,这是类加载器的问题:如果我这样做: new ClassPathResource(“jdbc.properties”); 它不起作用。 但是: new ClassPathResource(“jdbc.properties”,someClassIntheBundle.class.getClassLoader()); 工作得很好。 我相信Spring使用我的bundle所使用的自己的bundle的ClassLoader。 你知道解决这个棘手问题的方法吗? 谢谢,

UI属性不包含某些键

我有以下问题。 我需要获取UI属性: UIManager.getString(“OptionPane.okButtonText”) 返回字符串”OK” ,它的工作原理。 但是,如果我遍历UIDefaults键集,我永远不会得到键”OptionPane.okButtonText” 。 有谁知道它为什么会发生? 我以三种不同的方式获取UIDefaults ( UIManager.getDefaults() , UIManager.getLookAndFeel().getDefaults()和UIManager.getLookAndFeelDefaults() ),但这些都没有。 编辑 :我还找到了类JFileChooser 的属性列表 ,其中包含一些未出现在UIDefaults键集中的属性。 问题是:如何以编程方式获取所有这些属性? 编辑 :代码示例: UIDefaults defaults = UIManager.getDefaults(); String thekey = “OptionPane.okButtonText”; System.out.println(thekey + “: ” + UIManager.getString(thekey)); for (Enumeration e = defaults.keys(); e.hasMoreElements();) { Object key = e.nextElement(); System.out.println(key + “: ” + defaults.get(key)); } 此代码返回打印这些属性 。 […]

获取文件创建的日期/时间

这似乎是一个非常直截了当的问题,但我无法在网上找到明确的答案。 如何通过Java的文件管理器获取文件的创建日期/时间? 除了文件的名称,我还能得到关于文件的“属性”的其他内容吗?

如何让struts2看到我的属性文件

嗨我有这个项目结构 并在我的index.jsp我有这个代码: 我的content.property文件如下所示: index.hello = Hello user./n/r Please login index.login = Login index.password = Password index.title = Login Page 当我启动项目时,struts2没有从我的属性文件中获取信息。 请告诉我我错了什么我在互联网上找不到任何有用的东西请帮助我谢谢=)

将resourcebundle读为UTF-8。 getString()方法似乎将编码更改为ISO-8859

我有幸将完整的工作区,项目和文件的编码更改为UTF-8编码。 我们有几个Resourcebundles,用于使用unicode编写特殊字符。 我们还希望通过切换到UTF-8来摆脱那些unicode的东西,所以我也改变了Resourcebundles(.properties)文件的编码并替换了Unicode字符。 我们还有德国资源捆绑和一些像 Ä,Ö,Ü,ß。 ä,ö,ü以及像“或”这样的特殊字符 在浏览器中未正确显示。 例: Resourcebundleentry: executeShellCommand.label =Shellkommandoausführen 结果在浏览器中: 使用Java.util.ResourceBundle.getString(String key)方法读取resourcebundle: public String getLocalizedString(ResourceBundle bundle, String key) { try { System.out.println(“getLocalizedString, key: ” + key + “, resourcebundle: ” + bundle.getString(key)); return bundle.getString(key); } catch (MissingResourceException e) { return key; } } 如果我检查上面的Sysout的输出我得到以下: getLocalizedString, key: executeShellCommand.label, resourcebundle: Shellkommando ausführen 似乎getString(key)方法在将字符串从字符串读取到标准resourcbundleencoding(ISO-8859)时更改字符的编码 。 我试图解决这个问题: […]

如何在Javascript中访问模型属性

我想在Javascript中访问模型属性。 我使用以下代码: model.addAttribute(“data”, responseDTO); 我的DTO课程: public class ResponseDTO { private List errors; private Boolean actionPassed; private String dataRequestName; // and setter getter for all fields } 我尝试使用以下方式访问DTO: var data = “${data}”; 但是它给了我一个responseDTO的字符串表示,即com.req.dto.ResponseDTO@115f4ea 。 我可以使用以下方法成功访问DTO内的字段: var data = “${data.actionPassed}”; 但这不适用于DTO中的errors属性,因为它是ObjectError的List 。 如何在Javascript中获得完整的responseDTO对象? 谢谢! 编辑: 最初我使用的是jquery.post $.post(‘ajax/test.html’, function(data) { // Here I was able to retrieve every […]

不同属性的双向绑定

我只是试图绑定一个Integer和一个String属性。 经过一些谷歌搜索后,应该可以使用以下两种方法之一: public static void bindBidirectional(Property stringProperty, 属性otherProperty,StringConverter转换器) public static void bindBidirectional(Property stringProperty, 属性otherProperty,java.text.Format格式) 不幸的是,这似乎对我不起作用。 我究竟做错了什么? import java.text.Format; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.util.converter.IntegerStringConverter; public class BiderectionalBinding { public static void main(String[] args) { SimpleIntegerProperty intProp = new SimpleIntegerProperty(); SimpleStringProperty textProp = new SimpleStringProperty(); Bindings.bindBidirectional(textProp, intProp, new IntegerStringConverter()); intProp.set(2); System.out.println(textProp); textProp.set(“8”); System.out.println(intProp); } […]

在Hadoop中传播自定义配置值

在Map / Reduce期间,有没有办法设置和(稍后)在Hadoop中获取自定义配置对象? 例如,假设一个应用程序预处理一个大文件并动态确定与该文件相关的一些特征。 此外,假设这些特征保存在自定义Java对象中(例如, Properties对象,但不是唯一的,因为一些可能不是字符串),并且随后对于每个映射和减少作业都是必需的。 应用程序如何“传播”此配置,以便每个映射器和reducerfunction可以在需要时访问它? 一种方法可能是使用JobConf类的set(String, String)方法,例如,通过第二个参数传递序列化为JSON字符串的配置对象,但这可能是太多的黑客然后适当无论如何,每个Mapper和Reducer都必须访问JobConf实例(例如,遵循前面问题中建议的方法)。