NoSuchBeanDefinitionException for annotated classess alone - spring

Am getting org.springframework.beans.factory.NoSuchBeanDefinitionException
for the Classes for which I have used annotation (#Service)
I have mentioned the package scan correctly

This is a blunder mistake in deed. But just posting the answer because, many might do the same.
I was using Eclipse to prepare the JAR file. Eclipse did not pack the class files properly, so spring could not load the beans

Related

Equivalent of org.springframework.boot.context.embedded.FilterRegistrationBean for non-Boot Spring project?

I'm trying to implement external session handling in Spring, as per this tutorial. I'm having some trouble adding the right filter though. Spring Boot appears to have defined the proper bean/filter, but my project is not Spring Boot, so it cannot find the FilterRegistrationBean. Is there some sort of equivalent to this class in non-Boot versions of Spring? I also tried org.springframework.web.context.embedded.FilterRegistrationBean, but can't get it to import properly (it looks like this documentation refers to a SNAPSHOT version, so perhaps this package was never part of a proper release).
Depending on your container configuration, web.xml or ServletContainerInitializer, you can register a DelegatingFilterProxy filter and make it refer, by name, to a Filter bean you've declared in your ApplicationContext.

Classloader issue on Mule server

I am running my application on mule server. Mule server has there own sets of jars and my application that is running on mule server also has few jars. While working on Spring batch I found that JettisonMappedXmlDriver class exists in my application xstream jar as well as mule server jar as well. This class internally refer MappedXMLOutputFactory class that is in jettision jar which is also in my application but some how I am getting classnotfound error for MappedXMLOutputFactory class. This looks like class-loader issue.
If I add jettision jar in mule server then everything work fine but, I can't add this jar on my production environment. Can some body tell me how do I force to load the class from my application jettision jar file. It looks weird to me as classloader should have load MappedXMLOutputFactory class from jettision jar that is in my application folder like it is doing for other classes.
Please let me know if anybody found such issue.
The Mule application classloader is configurable: http://www.mulesoft.org/documentation/display/current/Classloader+Control+in+Mule
So just configure your application's classloader to first look at the JARs it embeds in /lib before deferring to the Mule System classloader.
You will encounter this issue if you have multiple versions of the same class in differnet jars, albeit with different method signatures. The ClassNotFound Error is usually not the only exception that occurs, you will often see another one before that, typically a "NoSuchMethodException" which forces class loader to unload the offending class.
I would suggest using maven or gradle to assemble your application and then use the dependency:tree target to query version conflicts.

Maven web project with JPA, Spring, Hibernate

I am getting started with with JPA. I am not running the project in a JEE container, simply using Tomcat. I want to test my DAOs (even though I read somewhere that DAOs may not be relevant with ORMs today) and have minimal dependencies on Spring and Hibernate.
Gist for relevant codes and configuration.
Problems I am facing are
bean of type UserDao cannot be found and hence cannot be injected resulting in error, even though I can see that it is created as it's constructor runs and I have done syso there, BUT
EntityManager is Null when UserDao is initialized
If I change the test-config.xml to use persistence.xml which is configured for MySQL database, it creates all tables, but same errors. hsqldb-persistence.xml is configured to use in-memory db.
Project Structure as it appears in Eclipse. When I run the TestUserDao it read correctly everything from hsqldb-persistence.xml which is in /src/test/java/resources/WEB-INF/ directory.
Appreciate any help.
Thankyou.

Java EE 6 - Why does an interceptor project need to be declared as ejb-jar and not simply a jar?

I was able to determine what I needed to do to get my interceptor working; however, I don't understand why I had to do that. All of the projects I am using my interceptor project in are either jar / war and CDI-enabled.
I thought CDI covered both EJB beans, regular POJO beans, properties, and anything resolveable via EL. And ... that to register an interceptor for CDI beans, I could simply declare it in beans.xml. None of my projects are EARs.
Now that I have it working by building the project as an ejb-jar, that is the main thing, but am I wrong in thinking it should work in beans.xml alone and building the project as just a regular jar?
Please point me to any documentation that specifies this clearly, everything on oracle's site indicates beans.xml should suffice.
Walter

FileNotFoundException in a testing a Maven module

I'm working on a recently mavenized legacy project with following multi-modular structure:
Parent:
Web
Service
Dao
("Service" module is dependent on "Dao" module)
Problem: some tests of Service classes call DAO code that creates beans using Spring's ClassPathXmlApplicationContext (this part is not really DAOs but caching related). Since, ClassPathXmlApplicationContext uses spring config xml of the DAO module - the Service tests fail throwing FileNotFoundException. I think this is because tests run in Service module and the spring config xml being referred lies in Dao module.
Please advise on how can I resolve the above issue in tests referring to code/resources of other modules?
Put a copy of the Spring configuration under src/test/resources in the Service module. Quite often you want a different configuration for testing anyway, but also it means your tests are less dependent on configuration changes in another module.

Resources