【问题标题】:accessing websphere 8 shareLib path frim Spring java code从 Spring java 代码访问 websphere 8 共享 Lib 路径
【发布时间】:2016-09-28 19:13:59
【问题描述】:

我正在制作 Spring 4.1.4 REST 服务并将其部署到本地 Windows 7 中的 websphere 应用程序服务器 8。

我已经创建了一个如下的共享库,并引用了受人尊敬的战争文件 sharedLib configuration

在那个位置,我将我的属性文件保存为 /abc/application.properties

loaction of the abc folder in APPSERVER

代码: 我正在尝试在 spring-rest.xml 中加载如下文件

<bean id="fileSystemResource" class="org.springframework.core.io.FileSystemResource">

    <constructor-arg value="#{systemProperties['sharedLib']}/abc/">
    </constructor-arg>
</bean>
 <bean id="propertyLoader" name="propertyLoader"     class="com.framework.RuntimeEnvironmentPropertiesConfigurer">

  <property name="propertyLocation" ref="fileSystemResource" /> 
  </bean>

我的属性加载器类:工作正常 :::

 public class RuntimeEnvironmentPropertiesConfigurer  extends     PropertyPlaceholderConfigurer implements InitializingBean,RuntimeEnvironmentInterface  {



/** The Environment */
public String environment;

/** The Property Location */
public FileSystemResource propertyLocation;

但遗憾的是,这是在我的 C:/drive 中搜索 abc 文件夹。

如果我在 C:/abc/application.properties.. 中保留以下内容,那么我的应用程序属性将被获取。并且应用程序运行良好所以加载 Bean 没有问题。

还在 pom.xml 中提供了我的依赖项,不确定是否需要添加任何其他依赖项。

<properties>
<springframework.version>4.1.4.RELEASE</springframework.version>
<jackson.library>2.7.5</jackson.library>
</properties>
<dependencies>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>4.1.4.RELEASE</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>4.1.4.RELEASE</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.1.4.RELEASE</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>3.0.0.RELEASE</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>3.0.0.RELEASE</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.7.5</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.xerial</groupId>
  <artifactId>sqlite-jdbc</artifactId>
  <version>3.8.11.2</version>
  <scope>runtime</scope>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.9</version>
  <scope>compile</scope>
  <exclusions>
    <exclusion>
      <artifactId>mail</artifactId>
      <groupId>javax.mail</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jms</artifactId>
      <groupId>javax.jms</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jmxtools</artifactId>
      <groupId>com.sun.jdmk</groupId>
    </exclusion>
    <exclusion>
      <artifactId>jmxri</artifactId>
      <groupId>com.sun.jmx</groupId>
    </exclusion>
  </exclusions>
</dependency>

但我需要从共享库位置获取路径。 谁能帮我指出我所缺少的? 请回答我如何在 Spring 中实现这一点。

【问题讨论】:

  • sharedLib 是 JVM 自定义属性吗?并且您在 Spring xml 配置中创建了 RuntimeEnvironmentPropertiesConfigurer 类的实例?
  • @dbreaux "sharedLib" 是我在 WAS 环境变量中创建的共享库的名称,其中包含我保存属性文件的路径。是的,我有一个在我的 Spring xml 中创建的 RuntimeEnvironmentPropertiesConfigurer 类的实例......我想从 sharedLib 加载路径。
  • 已编辑 spring-rest.xml 代码 sn-p..plz 参考 :) @dbreaux

标签: java spring properties websphere websphere-8


【解决方案1】:

WebSphere 中的 Java 系统属性来自应用程序服务器的 Process Definition > Java Virtual Machine > Custom Properties,而不是来自 WebSphere variables

【讨论】:

  • @dbresux 是的,谢谢......这正是我错过的重点。对 sharedlib 和 jvm 属性感到困惑......添加了自定义属性,它就像魔术一样工作。
猜你喜欢
  • 2017-10-10
  • 2018-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多