JBoss 5.1: Spring #Resource annotation not working - spring

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.

Related

Using #Named with Quarkus

I used to use the standard annotations #Named and #Inject for dependency injection in my code, and the Spring annotation #Primary to force the usage of a specific implementation in case I have multi implementations.
Unfortunately, this is not working with Quarkus anymore. Is there any specific reason ?
Is there any solution that can work for both Quarkus and a Web Application (The library that I am implementing can be used in both type of applications)?
Thanks

Unable to extend BaseCommandController in Eclipse

I am new to Spring and I am trying to extend BaseCommandController but Eclipse doesn't show it. I can extend AbstractController but not BaseCommandController. I have added all jar files from spring-framework 4.2.2.RELEASE.
What should I do to solve this problem?
You are not able to extend BaseCommandController because it is deprecated since Spring 3 and got removed in Spring 4.
The Spring way is now to use annotations as mentioned in the deprecation comment:
#deprecated as of Spring 3.0, in favor of annotated controllers
You should have a look at the Getting Started guide of Spring MVC where you can find a good example of the #Controller annotation

Intellij spring boot integration

For some reason Intellij 13.1.3 doesn't detect the spring boot beans. Spring boot version is 1.1.1-Release. When i try to inject ObjectMapper in some component i get an error in the IDE "No bean of type ObjectMapper defined", however the application compiles and runs just fine and the ObjectMapper beans is visible in the /beans json.
I have added my application-context and my Application.java files to a spring facet and the IDE recognizes all my other beans that I manually defined, it just ignores the ones that come with Spring boot #EnableAutoConfiguration. Any idea how to solve that since its kinda tedious not to have the correct linking in the IDE and get errors all over the place. I would assume thats a common issue?
Thanks!
As an update for this answer: IntelliJ now supports Spring Boot. Must be at least R14. R15 is including some more integration.
Spring Boot is not supported yet, please watch http://youtrack.jetbrains.com/issue/IDEA-119230

Jetty 8, Weld - Injection isn't working

I'm trying to setup a project using Jetty 8 as the server (jetty-maven-plugin:8.1.11.v20130520), Weld for CDI (weld-servlet:2.0.1.Final), Hibernate for JPA (hibernate-entitymanager:4.2.2.Final, hibernate-jpa-2.0-api:1.0.1.Final) and Jersey for JAX-RS.
It seems that injections isn't working at all.
I tested whether the EntityManager is being injected, and the value was null.
The log doesn't show any errors or warnings while executing the server.
Am I missing something ?
If needed, I will post the log file to gist.
Here is the gist of all relevant files: https://gist.github.com/StalkingKillah/e986474b6885d83c7f8d
This is how I got it working for Jetty 9, and it should be basically the same for Jetty 8.
http://www.eclipse.org/jetty/documentation/current/framework-weld.html
It is easier to have the weld jar outside of the webapp as then you don't have to mess with tweaking the classes exposed to the webapp classloader like you are here (with the -org.eclipse.jetty bit for the ServletContext). I suspect there are more classes that would have to be added to that in order to make it work. You should get a note in the logging that says it is all enabled and active though.

JBOSS 5 and Spring 3 Validation Annotations

I have been trying to set up Spring 3 annotation-based validation, guided by http://static.springsource.org/spring/docs/3.0.0.RC3/spring-framework-reference/html/ch05s07.html. I am using JBOSS 5.0.1 server; however, upon invoking the #Valid annotation from the Controller. I received errors and found out it will require javax.validation.*;
Upon adding the validation-api-1.0.0.GA.jar (for javax.validation.*), I received complaints about it requiring Hibernate Validator 4+, which in turn requires Hibernate 3.5+. Finally, I discovered that JBOSS 5 does not support Hibernate 3.5+ because it uses JPA-2 and JBOSS 5 is tightly coupled to JPA-1.
At this point, my brain hurts.
Does anyone have a successful example of using Spring 3 annotation-based validation under JBOSS 5?
I finally figured out the answer to this. I basically reverted to using Hibernate Validator 3.1 using this example:
http://wheelersoftware.com/articles/hibernate-validator-3.html
Hope this helps anybody else.
I just wanted to add one more thing. I managed to wire Hibernate Validator 4.01 to JBOSS 5.01. The steps were as follows:
Remove hibernate-validator.jar from the JBOSS common/lib directory
Insert the validation-api-1.0.0.GA.jar, hibernate-validator-4.1.0.Final.jar into your project's WEB-INF/lib directory.

Resources