作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Vaadin ClassResource 类从将与 WAR 一起部署的文件中加载我的数据库连接属性,但我似乎找不到该文件。我正在使用 Vaadin 6.5.2、Tomcat 7.0.6,并且我已将我的“app.properties”文件与我的应用程序主文件放在同一个包中。
我的代码在 Scala 中。这是我的尝试:
val cr = new ClassResource("app.properties",this) // "this" is the application
debug("resource mimeType = {}",cr.getMIMEType)
debug("resource bufferSize = {}", cr.getBufferSize)
debug("resource cacheTime = {}",cr.getCacheTime)
debug("resource fileName = {}", cr.getFilename)
val ds = cr.getStream
if (ds != null) {
debug("download stream bufferSize = {}", ds.getBufferSize)
debug("download stream cacheTime = {}",ds.getCacheTime)
val is = ds.getStream // get InputStream
if (is != null) {
val props = new Properties
props.load(is)
val dbHost = props.get("db.host").asInstanceOf[String]
val dbName = props.get("db.name").asInstanceOf[String]
val dbPort = props.get("db.port").asInstanceOf[String]
val dbUser = props.get("db.user").asInstanceOf[String]
val dbPass = props.get("db.pass").asInstanceOf[String]
val dbUri = props.get("db.uri").asInstanceOf[String]
} else {
debug("Input stream was null")
}
} else {
debug("Download stream was null")
}
结果如下:
08:51:59.617 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - resource mimeType = application/octet-stream
08:51:59.620 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - resource bufferSize = 0
08:51:59.621 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - resource cacheTime = 86400000
08:51:59.621 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - resource fileName = app.properties
08:51:59.621 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - download stream bufferSize = 0
08:51:59.621 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - download stream cacheTime = 86400000
08:51:59.621 ["http-bio-8084"-exec-11] DEBUG c.sentientswarm.propdesk.AppConfig$ - Input stream was null
我已经尝试将配置文件放在不同的位置,包括 src 的顶部、包含主题的 VAADIN 文件夹的顶部以及它当前所在的位置(与主应用程序在同一个包中),但结果总是一样的。谁能告诉我我做错了什么???
最佳答案
这就是我们的做法。
InputStream is=null;
try
{
is=Application.class.getClassLoader().getResourceAsStream("Application.properties");
}
catch(Exception x)
{
log.error("Error loading 'Application.properties' properties",x);
return null;
}
if (is!=null)
{
try
{
Properties props=new Properties();
props.load(is);
return(props);
}
catch (IOException e)
{
log.error("Error reading properties 'Application.properties' ",e);
}
}
return(null);
但公平地说,我们不会制造 war 并让我们的应用程序保持安全。请记住,Application.class
不是 Vaadin 应用程序,而是我们自己的 Vaadin 应用程序包装器。
关于scala - 找不到 Vaadin ClassResource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5222632/
我正在尝试使用 Vaadin ClassResource 类从将与 WAR 一起部署的文件中加载我的数据库连接属性,但我似乎找不到该文件。我正在使用 Vaadin 6.5.2、Tomcat 7.0.6
我创建了一个 Vaadin 应用程序,它尝试使用 ClassResource vaadin 类来加载一些图标以及一些 vaadin 组件,但我在最终应用程序中看不到图标。在图标位置,我看到一个蓝色问号
我是一名优秀的程序员,十分优秀!