Spring Integration - Externalizing JDBC Queries

后端 未结 2 1410
南笙
南笙 2020-12-21 15:21

Is there a simple way to externalize big sql queries from jdbc outbound gateways, instead of inlining it? The reason being that we\'re having to many big queries to make, an

相关标签:
2条回答
  • 2020-12-21 15:53

    Yes, you can put them in a properties file, and use properties placeholders ${...} to resolve them, or you can use SpEL...

    "#{myQueryBean.queryOne}"
    

    where myQueryBean is a <bean/> that's an instance of a class with a method...

    public String getQueryOne() {...}
    

    or a static constant on a class...

    "#{T(foo.Queries).QUERY_ONE}"
    
    public static final String QUERY_ONE = "...";
    
    0 讨论(0)
  • 2020-12-21 15:56

    You can define your queries in XML as spring beans:

    <bean id="exampleQuerySql" class="java.lang.String">
        <constructor-arg>
          <value>
              <![CDATA[
    select * from foo
    where whatever_ind = 'A'
              ]]>
          </value>
        </constructor-arg>
    </bean> 
    

    Using CDATA the query text can include newlines, angle brackets, etc., so it's legible and you can cut and paste it directly into a SQL tool.

    You can refer to the bean using SpEL.

    0 讨论(0)
提交回复
热议问题