Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从applicationcontext.xml获取空值_Java_Spring_Spring Mvc_Struts2_Applicationcontext - Fatal编程技术网

Java 从applicationcontext.xml获取空值

Java 从applicationcontext.xml获取空值,java,spring,spring-mvc,struts2,applicationcontext,Java,Spring,Spring Mvc,Struts2,Applicationcontext,我正在开发struts2应用程序,后端为弹簧。 我们正在使用database.properties文件,条目如下: jdbc.url=jdbc:mysql://localhost:3306/myDb jdbc.username=root jdbc.password=rooooot jdbc.csvlocation=C:\myCSV 我在database.properties中添加了以下新条目 enhancePerf.Flag=true 在applicationcontext.x

我正在开发struts2应用程序,后端为弹簧。
我们正在使用database.properties文件,条目如下:

jdbc.url=jdbc:mysql://localhost:3306/myDb  
jdbc.username=root  
jdbc.password=rooooot  
jdbc.csvlocation=C:\myCSV
我在database.properties中添加了以下新条目

enhancePerf.Flag=true 
在applicationcontext.xml中,我获取如下值:-

<bean id="userLogin" scope="prototype"  
        class="com.hello.something.actions.UserLoginAction">  
        <property name="perfEnhance" value="${enhancePerf.Flag}"/>  
</bean>

在UserLoginAction中声明了一个全局变量perfEnhance,并形成了相同的setters和getter方法之后,我仍然没有得到该值

我点击了以下链接:-


请提供建议。

请将以下内容替换为您的
属性PlaceHolderConfiguration
bean:

<context:property-placeholder location="classpath:path/to/database.properties"
                              ignore-unresolvable="false"/>
您必须在
Action servlet.xml
中使用“/users”名称定义该操作的bean:

<bean name="/users" .../>

stacktrace是否出现异常?没有。。我没有任何例外。我刚得到perfEnhance的值为null。您定义了属性文件的位置了吗?您的属性文件是否位于正确位置?我在applicationcontext.xml中声明了它,如下所示:通过以下链接,但未发现任何新内容:(我在applicationcontext.xml中发现以下错误:元素“context:property placeholder”的前缀“context”未绑定。您必须添加名称空间定义。我用示例更新了答案仍然没有乐趣:(.值可以在服务和DAO中获取,但不能在操作中获取。此外,当我使用ignore unsolvable=“false”时,我会收到一个异常为您的问题发布异常。还要确保在
struts.xml
中使用的是bean名称,而不是完整的类名。还要确保查看我添加的Spring文档链接,并使用
ContextLoaderPlugin
插件。
<bean name="/users" .../>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd 
       http://www.springframework.org/schema/util 
       http://www.springframework.org/schema/util/spring-util.xsd">