Apache commons configuration compatibility with PropertyPlaceHolderConfigurer - spring

I am trying to use apache commons configuration replacing a PropertiesFactoryBean in a spring application.
It seems to me but commons configuration framework is not compatible with PropertyPlaceHolderConfigurer nor with #Value annotations.
If you suggest me a solution please note that I have spring configured only with xml.
Thanks,
Mario

You are correct. commons-config is ancient, and wouldn't know an #nnotation from a garden-snail. #Value implies a ton of expensive mechanism involving reflection and inspection of annotation -- if you still need #Value, you might need to reconsider getting rid of Spring.

For future reference: the previous answer is no longer correct. Commons Configuration is able to interact with the PropertyPlaceholderConfigurer, see
http://commons.apache.org/proper/commons-configuration/userguide/howto_utilities.html#Use_Configuration_in_Spring for details.

Related

What are disadvantages of using Lombok in my Spring Boot RestApi?

I am using Lombok in my Spring Boot Rest Api. I searched a lot but could not found what I want to know about Lombok. My rest api is an enterprise level application which would be extend with more modules in future.
Should I use lombok? What are the major disadvantages of Lombok using in enterprise application?
My IDE is STS.
You have to know what Lombok really does under the hood.
For example, Lombok adds #java.beans.ConstructorProperties before constructors. This may be important if you use Jackson serialization.
See https://projectlombok.org/features/constructor
There are no special advantages or disadvantages of using Lombok in an enterprise application. Lombok itself and all its annotations are removed during compilation, so there will be no additional libraries at runtime.
Furthermore, if at any point later you'd decide against Lombok, you could remove it again by running delombok, which will give you the code that Lombok generates. So there is no real risk there (besides that it will of course take some time to delombok everything).
For a general (of course opinion-based) discussion on Lombok's (dis)advantages, see this answer.

List of Spring Boot provided beans?

Is there a list of beans provided by Spring Boot and its different modules? For example, I only recently discovered that Spring Boot already provides a configurable Jackson ObjectMapper bean. I would have never known that if not for reading up on an unrelated issue I was dealing with. Now I'm working with Spring JMS and am afraid that I am reinventing the wheel because Spring Boot may already have what I need and I just don't know about it. How are these beans discovered? They don't seem to be cataloged in any Spring documentation.
I would recommend starting with the reference documentation. While it doesn't list every bean that may be auto-configured, it does have documentation describing each feature area that may be auto-configured. For example, there are sections on Jackson's ObjectMapper and on JMS.
Each starter that Spring Boot offers is also a good indication of what it can auto-configure. Each first-party starter is listed in the documentation.

Spring boot with spring #Transactional works without enabling transactional management

In my spring boot application spring #Transactional annotation works without specifying #EnableTransactionManagement explicitly.
Is there any official documentation saying that it is enabled automatically?
Or there is something else happening .... ?
btw: I'm using Spring Data JPA
Yes, this is enabled as long as you have spring-tx and some transactional resource in your application. Effectively if you are using spring-boot-starter-jdbc or spring-boot-starter-data-jpa, Spring Boot will configure a DataSource for you, start Hibernate (in the latter case) and configure transaction management.
Not all "Enable" annotations require to be explicitly set. When there is a reasonable amount of things that we can check to validate it makes sense to configure that for you, we'll do it. In this case, if you have a DataSource you must probably want to have transactions. If you have JPA (and no JTA infrastructure), you probably want a JpaTransactionManager). If we auto-configure that, the easiest way to use it is via #Transactional so we'll enable that in that case as well.
I guess you kept asking to get some sort of "official" answer, so here's one.
#SpringBootApplication adds #EnableAutoConfiguration it detects Spring Data JPA on your classpath. According to it Spring registers PlatformTransactionManager - JpaTransactionManager, datasource, entitymanager, repositories.
Not sure there are precise articles, but there are proper answer on stack. An official spring sample article
#Transactional annotation can work fine if the "< tx:annotation-driven/ >" tag is in your Spring XML configuration. Look at this reference : http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/annotation/EnableTransactionManagement.html

Spring Boot, Velocity Tools

I'm trying to integrate spring boot with velocity tools but it still fails, the documentation did not find anything related to how to load velocity.properties, anyone have any help? Thank you.
I ran into some Boot/Velocity configuration issues this morning. You are right that the documentation is spare here.
If you are looking to use Velocity for Spring MVC templating, be sure to include spring-context-support on the classpath. Based on the behavior, it appears that Boot is doing some classpath autodetection here, and creates VelocityConfigurer and VelocityViewResolver beans if and only if spring-context-support is on the classpath.

JBoss 5.1: Spring #Resource annotation not working

I am working on an application using Spring 3 and Hibernate 3.5 with Java 1.6.
So far I've been using JBoss 4.2.1 and everything was fine.
Now while migrating to JBoss 5.1, I encountered lot of issues. One of them is that JBoss is ignoring the Spring #Resource annotation. I get the following exception:
java.lang.RuntimeException: mapped-name is required for serviceManager of deployment pol-1.0.war
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXmlResourceEnvRefs(WebResourceHandler.java:287)
at org.jboss.web.tomcat.service.injection.WebResourceHandler.loadXml(WebResourceHandler.java:325)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.processMetadata(TomcatInjectionContainer.java:550)
at org.jboss.web.tomcat.service.WebCtxLoader.start(WebCtxLoader.java:158)
It expects mapped-name for each #Resource like some ejb.
I've seen similar questions but they are without any answer e.g.:
#Resource annotation not working properly with JBoss5.0.1
Please advise.
Adi
Actually your problem is that JBoss doesn't ignore #Resource annotations - it tries to handle them according to EJB rules instead of leaving them to Spring.
Perhaps this feature can be disabled somewhere in JBoss configuration, but the simpliest solution would be to replace #Resource with #Autowired or #Inject.
Sounds like java annotations need namespace support.
Then it would be #Spring:Resource or #EJB:Resource.
Oracle, are you listening?
Short of namespace for Annotations, you could possibly try changing the order of the libraries in your classpath so java would see the Spring annotations first (or last), whichever ends up providing the desired outcome.

Resources