I am very new to spring and started using.
I have a requirement where i have something like properties
like regions..US,UK
Regions
-------
US
UK
And when i read US it shud have values something like
US
----
(KEY)primary----VALUE(primaryValue)
(KEY)secondary----VALUE(secondaryValue)
.
.
similarly
UK
--
(KEY)primary----VALUE(primaryValue)
(KEY)secondary----VALUE(secondaryValue)
.
.
and the regions might increase as requirement changes and the key value pairs below it too
Someone hint me so i can proceed
Thank you in advance
You need to create two bean a List and a Map, in other word List<Map> is you need
<bean id="regions" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="usMap" />
<ref bean="ukMap" />
</list>
</constructor-arg>
</bean>
and
<util:map id="usMap" map-class="java.util.HashMap">
<entry key="primary" value="someValue"/>
<entry key="secondary" value="someValue"/>
</util:map>
You can make different properties in according to region , when server will start all the properties file will load.You can make PropertiesFileReader.java file which will read u'r properties.
Related
I have a property defined in an xml file - that.xml
that.xml
that.xml code for toReferProperty
I need to refer to the property - 'toReferProperty' - under the bean - 'thatBean' - in the file - 'that.xml' - in the file 'this.xml' in the below way and then based on that I need to use a property 'newProperty in the 'constructor-arg' as below-
========
this.xml
thisd.xml code for newProperty
Questions 1: How do I refer to the 'toReferProperty' in that.xml in 'this.xml'?
Question 2: How to use the 'toReferProperty' in the IF else loop in XML syntax?
Question 3: How to refer to 'newProperty' in 'this.xml' in the 'constructor-arg' in same xml?
You can try something like this. If you are trying to do this for different environments, i would recommend using spring Profiles instead of if/else but here's what you need to answer your question.
that.xml
<bean id="someProperty" class="java.lang.String">
<constructor-arg value="Hello"/>
</bean>
<bean id="thatBean" class="someClass">
<property name="referProperty" ref="someProperty"/>
</bean>
this.xml
<import resource="that.xml" />
<bean id="thisBean" class="someClass">
<constructor-arg value="#{ ${someProperty} == Hello ? newValue1 : newValue2 }"/>
</bean>
I'm writing a parsing tool to compare the textual content of two bean XML files in Java. The text content changes and we need a way to run a script to make sure the textual content is the same. I know we have org.w3c.dom which has a method getElementsByTagName("tag_name") and that returns a node list in the XML document. I'm wondering if anyone knows of a way to do this using the class name? I've been searching around but haven't been able to solve this yet.
<bean class="com.mycompany.myText" id="Q1.4">
<property name="name">
<value>Q1.4</value>
</property>
<property name="text">
<value>This is text one</value>
</property>
<property name="retired">
<value>true</value>
</property>
</bean>
<bean class="com.mycompany.myText" id="Q1.5">
<property name="name">
<value>Q1.5</value>
</property>
<property name="text">
<value>This is text two</value>
</property>
<property name="retired">
<value>true</value>
</property>
</bean>
I can't use the 'bean' element name as there are several other beans whith non relevant stuff I need only the ones with the class com.mycompany.myText and the value I'm trying to extract is property name=text - the text content
Any help here would be appreciated. Also as a side note I should mention that we have no direct control of how the XML file is managed and structured as it's fed to us from a 3rd party.
As you say, you need to select tags by their attributes.
You could use XPath to achieve this. See those resources:
http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/
https://stackoverflow.com/a/24220968/6377268
The expression would be something like this
/bean[#class='com.mycompany.myText']/property[#name='text']/value
I hope I could help at least a little bit.
I am new to Spring and trying to read a complex file using FlatFileItemReader in Spring batch. The input file has structure as below. The sample below is one records and file has many records like this. Line starting with H is a Header Record and with F is a footer records. In between there are transaction records of type 10500, 10501, 405, 505. I am able to read this file using MultiLineItemReader.
I have created FieldSetMapper and Tokenizer and able to parse the file and get to individual fields. Only issue I am facing is that for records types 10500 and 10501 they can appear multiple times in between Header and Footer and when I am reading the file I am just getting the last read values and the previous records are just not appearing in reading. I know I am doing something silly but not able to understand. Has anybody had any experience reading such type of file.
H00025888222 444233DD 33232323232
105000000 0000 0
10501 1 2222222
105000000 0000 1
10501 1 2222223
40500 1222222
50500 21
F00555 5555 0
If the you just have multiple types of lines, but the lines are each standalone, then PatternMatchingCompositeLineMapper is probably what you're looking for.
<bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="#{jobParameters['input.file']}" />
<property name="lineMapper" ref="patternMatchingMapper" />
<property name="strict" value="true" />
</bean>
<bean id="patternMatchingMapper" class="org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper">
<property name="tokenizers">
<map>
<entry key="LINEA*" value-ref="tokenizerA" />
<entry key="LINEB*" value-ref="tokenizerB" />
</map>
</property>
<property name="fieldSetMappers">
<map>
<entry key="*" value-ref="beanWrapperFieldSetMapper" />
</map>
</property>
</bean>
If they are related (multiple lines need to be combined to make one object, you make consider SingleItemPeekableItemReader, described briefly here).
I have a standard Spring class that accepts a String array. I know that Spring will take care of splitting a comma separated String into an array, but I'm unaware of how it does it under the hood.
The question that led me to this is whether the Strings will become trimmed after being split, but I would like to know how to see this under the hood activity as well if other future issues arise.
<bean id="allServicersDelimitedLineTokenizer"
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="col1,col2,col3,col4" />
</bean>
is the same as?
<bean id="allServicersDelimitedLineTokenizer"
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="col1 , col2, col3, col4" />
</bean>
I have tiles set up in my spring project as the view handler like this:
<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver" />
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/views/**/tiles.xml</value>
</list>
</property>
</bean>
I'd like to use EL to access the session scope inside tiles.xml, for resolving a jsp file name. This should be possible if i use CompleteAutoloadTilesContainerFactory, as described here:
http://tiles.apache.org/framework/tutorial/advanced/el-support.html
How can I set my spring tiles configuration to allow this. Ive tried using EL as it is currently set up but the EL is not parsed.
Figured it out, i left the configuration exactly the same and just included tiles-el.jar . No need to include tiles-extras.jar though. NFV
You may try setting completeAutoload property of TilesConfigurer class. Please see reference doc TilesConfirurer.
This may require Tiles-Extras 2.2 jar file.