2016-05-26 4 views
1

は、そのようなファイルは動作しません:春4つのプロパティファイルには、私がdb.propertiesに豆の設定でハードコードさデシベルの設定を交換しようとした

@Configuration 
public class BeansConfig { 

    private @Value("#{database['db.url']}") String dbURL; 

    public ComboPooledDataSource dataSource() throws PropertyVetoException { 
    ComboPooledDataSource dataSource = new ComboPooledDataSource(); 
    dataSource.setDriverClass("something"); 
    dataSource.setJdbcUrl(dbURL); 
    dataSource.setUser("something") 
    dataSource.setPassword("something") 
    return dataSource; 
    } 
} 

しかし、それは仕事をdoesntの。そして強調表示されているので、Ctrlキーを押しながらクリックすると.propertiesファイルが表示されます。 しかし、私がアプリを起動しているときは、うまく動作しません。それはDBに到達しようとしていますが、それはしません。私が変更しようとしているときには、 "url"自体の上にdbURL自体がスムーズに動く。

試してみたが、それは役に立たなかった。

EDIT

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.4"> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath:*/appSecurity.xml 
     classpath:*/appContext.xml 
    </param-value> 
</context-param> 

<servlet> 
    <servlet-name>app</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      classpath:*/appContext.xml 
     </param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>app</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Spring Security --> 
<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

+0

注を行うことができます。コンストラクタの前に 'dbURL'の値をチェックしている場合、' null'になります。 – Maroun

+0

@Maroun Marounはハードコードされた文字列とまったく同じですか? – ottercoder

+0

'PropertySourcesPlaceholderConfigurer' beanを追加しましたか? – sidgate

答えて

0

お持ちの場合は、あなたの特性で

db.url = jdbc:mysql://localhost:3306/livedumpは、ファイル(それはapplication.propertiesであるか、またはクラスに注釈を付けるために持っています@PropertySource("classpath:name_of_file.properties"))。

あなたは、コンストラクタが終了した後に*のみ*割り当てられるだろうと

@Value("${db.url}") 
String dbURL; 
+0

@value(「$ {db.url}」)ハイライト表示してOPを編集できます。この理由は動作しないことが表示されていませんまた、それは助けにはならない。 – ottercoder

関連する問題