how to add spring tiles configuration feature through xml?...for example
suppose If I've 1000+ tiles resolver xml files.how can I add those xml files ? I need to add all the xml files or is there any new feature to inject all files?
You don't need to configure each view definition file. TilesConfigurer definitions property support wildcard characters.
In the following example TilesConfigurer will try to load all views.xml under any subpath of /WEB-INF/views/
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/layouts/layouts.xml</value>
<!-- Scan views directory for Tiles configurations -->
<value>/WEB-INF/views/**/views.xml</value>
</list>
</property>
</bean>
Hope this helps!
Related
In my project we are using below configuration to the load configuration file in spring context.
<!-- Configuration property files -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
<property name="locations">
<list>
<value>jdbc.properties</value>
<value>jms.properties</value>
<value>config.properties</value>
<value>override.properties</value>
</list>
</property>
</bean>
Later I want read config.properties as Boolean value in JSP Page. then based on conditions I want to rendered some comment box in UI.
Do have any work around on this. Please help me with your suggestion, Thanks in advance
I'm using spring + hibernate in my application.
I need to map the entities that are annoted by hibernate annotations.
I have this configuartion.
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.example.repositoryComment.Model1</value>
<value>com.example.repositoryControlUpload.Model2</value>
<value>com.example.repositoryCycleTicketSummary.Model3</value>
</list>
</property>
I'd like that the entities configuration stay in another file.
Exemplo:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
filesThatContainsModels
</list>
</property>
This classes (Model1, Model2, Model3) are annoted by hibernate.
I don't use packagesToScan, because my warmup need to be fast.
There is way for configuration only the class that annoted, but not using packagesToScan?
Thanks
One option at build-time would be to take advantage of annotation processing.
Basically a custom annotation processor will scan your source files at build time and generate a list of all files found to be annotated with #Entity. It takes this list of classes along with an external property file that describes your static SessionFactory configuration and it generates your spring XML file as applicationContext-persistence.xml.
You then just make sure your main applicationContext.xml imports that file for runtime.
Another alternative would actually to use the packagesToScan property. But rather than do what a lot of developers do and point it to the root package of your application, provide the property with a more restrictive list of packages that represent exactly where it should look, helping it avoid inspecting unnecessary classes. For example:
<property name="packagesToScan">
<array>
<value>com.company.application.feature1.persistence</value>
<value>com.company.application.feature2.persistence</value>
...
</array>
</property>
But I honestly think you're over optimizing. If you have this type of bootstrap performance issues, there has to be something else going wrong here to give you cause for concern.
I have worked on a monolithic application with tens of thousands of class files where the scan pointed to the package root of the application and it didn't take any more than a few seconds to bootstrap the Hibernate persistence classes.
I am using Spring 3.0.5 and InternalResourceViewResolver to resolving the views. Now if I put all the .jsp files into WEB-INF/pages/view and use configuration like:
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/view</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
the pages resolving correctly.
But for different module I want to put my .jsp files in separate folders. For example package WEB-INF/pages/view/booking and WEB-INF/pages/view/quote will contain .jsp files for Booking and Quote module correspondingly.
How can I do such configuration ?
I'm not sure such configuration is easily possible. But there is another easy approach to having your views in different directories. Just use the common part of the path as prefix (/WEB-INF/pages/view/) in your view resolver configuration and then return the relative path of your view to the specified prefix from your controller:
booking/home -> will be resolved to /WEB-INF/pages/view/booking/home.jsp
quote/home -> will be resolved to /WEB-INF/pages/view/quote/home.jsp
I choose to use Spring Jaxb2Marshaller to support JAXB in my project, but I cannot specify a schema file in element oxm:jaxb2-marshaller, I found only a contextPath property, nothing about schema.
Must I use the old Jaxb2Marshaller config style (using beans:bean element)?
The class Jaxb2Marshaller has a schema property, try this sample of code.
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>my.package.ResponseObj</value>
</list>
</property>
<!-- Possibly include schema for validation -->
<property name="schema" value="classpath:schema.xsd"/>
</bean>
EDIT :
I think that you can't specify an XML schema directly in the config file with the new OXM balise. There is no xml element or attribut for this in the OXM XSD. But you can use the new #XmlSchema annotation directly in your "classe to bound". Look this documentation.
I want to load multiple properties files using <util:properties> tag in a spring 3 application.
I searched on the blogs, but cannot get the correct path to do this.
Hopefully somebody give me the answer to overcome this problem.
Actually <util:properties> is just convenient tag for org.springframework.beans.factory.config.PropertiesFactoryBean. And PropertiesFactoryBean does support multiple locations.
So it is possible to create bean with Properties this way:
<bean id="myProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:myprops-common.properties</value>
<value>classpath:myprops-override.properties</value>
<value>classpath:some-more-props-here.properties</value>
</list>
</property>
</bean>
My solution
<context:property-placeholder location="classpath*:*.properties,file:/some/other/path/*.properties" />
util:properties seems to support only 1 properties file (reference). You might want to use the configuration suggested by #peperg.