0

バックエンド用のスプリングを備えた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 を宣言し、同じセッターとゲッター メソッドを作成した後、まだ値を取得できません。

次のリンクをたどりました: -
http://www.roseindia.net/tutorial/spring/spring3/web/applicationcontext.xml-properties-file.html

お知らせ下さい。

4

1 に答える 1

0

PropertyPlaceholderConfigurerBeanの代わりに、次のように入力します。

<context:property-placeholder location="classpath:path/to/database.properties"
                              ignore-unresolvable="false"/>

このように、プロパティが見つからない場合は、文句を言います。そうしないと、クラスパスに別の「database.properties」ファイルがあり、そのようなプロパティがないように見えます。

「path/to/database.properties」がクラスパスに含まれていることを確認してください。それdatabase.properties自体がクラスパスである場合、「パス/宛先」は必要ありません=>ただclasspath:database.properties

また、を使用してアクションをBeanとして管理するようにSpringを構成する必要があります。またContextLoaderPlugin、Struts構成でBean名を使用する必要があります。struts-config.xmlファイルに次のものがある場合:

<action path="/users" .../> 

action-servlet.xmlアクションのBeanを「/users」という名前で次のように定義する必要があります。

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

Springの公式ドキュメントからSpringStrutsIntegrationをご覧ください。

コメントに答えるために編集してください:

contextは、使用されるXMLファイルで定義する必要があるXML名前空間です。

<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">
于 2011-10-14T04:52:54.310 に答える