Why Spring uses the configuration in ".xml" file format,
Is there any possibility to configure in ".properties" file?
Starting with version 3.0, and further enhanced in 3.1, Spring now has complete support for Java-based configuration.
http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/#beans-java
http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html
Xml was the de-facto method of specifying configuration when Spring was in its infancy. As of spring3, it is possible to use annotations instead of xml.
However, you will still require to load the spring context first (using xml configuration file) and the rest of the spring based configuration would be loaded through the spring annotations.
Yes, you can specify the properties file separately for name-value pairs
<context:property-placeholder location="classpath:filename.properties"/>
Related
Is it possible to have spring integration xml configuration and spring boot java annotation configuration at the same time? Can you please refer with an example on this?
What is the best practice for this?
Thanks
As Marten pointed out it is fully fine to combine Spring Boot with an XML configuration. See Spring Boot docs: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using.configuration-classes.importing-xml-configuration
If you absolutely must use XML based configuration, we recommend that you still start with a #Configuration class. You can then use an #ImportResource annotation to load XML configuration files.
And here is the sample: https://github.com/spring-projects/spring-boot/blob/main/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-xml/src/test/java/smoketest/xml/SampleSpringXmlPlaceholderBeanDefinitionTests.java
I have the project that has very huge legacy spring xml configuration (about 500 beans).
This configuration is too difficult to support.
The best way is convert xml to java based configuration, but it difficult to do manualy.
Is anybody known any tools for automatically convertaion Spring xml configuration to Spring java based configuration?
We have some xml that uses capitol letters for all fields. Spring boot automatically uses jackson which does not work well with this. I have the xml "jaxb"d into java objects that tell it to use the capitol letters. However spring always seems to use Jackson.
Anyway to force it to use Jaxb?
You can find here a list of commonly used in spring-boot properties for your application.properties file. You probably need:
spring.jackson.property-naming-strategy=UPPER_CAMEL_CASE
Here are the available naming strategies for Jackson.
If you insist on Jaxb I believe it will be used by spring boot unless you include jackson-dataformat-xml in your classpath (may have to exclude it).
tl/dr (How) Is it possible to use a jar library, that uses Spring Boot for configuration in a non Spring Boot (regular old-school Spring) server.
We have the problem, that we have a Spring server, that is from the pre-Boot times and we want to create a new library for it. We would like to use Spring Boot in the library (i.e. #EnableAutoConfiguration for configuration). To include the library we have put an spring.xml into the library that enables component-scan inside the library. The classes inside the library use #EnableAutoConfiguration and #EnableWebSecurity to enable configuration and security.
If we include now the library into our server and import the XML file from the library into the server's XML file, only parts of the configuration are working. The #RequestMappings in the library are working and the interfaces are available. However Spring security fails to register it's default filter chain, leading to ugly errors, where the regular Spring Boot config should already work with AnonymousAuthorizationFilter, etc.
We debugged, that the FilterRegistrationBean in spring security is never configured when running that way (and is, if we are running as a Spring Boot application).
So is there a common way how to deal with Spring Boot enabled libraries inside old-school Spring servers?
Is placing a single XML to enable component-scan in the library and importing this XML inside the main server's XML the correct way to include Spring Boot libraries (and how would be the best way, if the server would use Spring Boot itself)?
Does anyone know of the issue with a missing Spring Security filter chain?
PS: I know that we can add the required filters manually. However if we would do that, we would anyway get rid of Spring Boot completely in the library, so this question mainly aims for how to do it with Spring Boot. Of course if it is the wrong way to enable Spring Boot inside a library, please also mention that :-)
I am new to Spring Security and I was trying to add spring security namespace. Do I need to add this to serverlet-context.xml. In my Eclipse>Spring MVC project it looks like that is the only file that has namespace information. The other two xml files are web.xml & root-context.xml.
Where do I put the namespace information?
It will depend on how your app is split up and what you want to secure. The web.xml file is not a spring configuration file so you can't put Spring Security configuration in there. Putting it in the servlet-context.xml should be OK.
However, if you are at this stage, you should probably start with one of the sample applications. Also take a look at this getting started guide on spring.io which uses Java configuration with Spring Boot which is a much nicer combination.