Hello guys,
Recently I was trying to figure out how to use @Configurable annotation for one of my class projects. Since @Configurable needs some kind of aspectj weaving, I decided to use compile-time-weaving. The strange part is that when I try to use @Configurable(dependencyCheck=true) it always throws a UnsatisfiedException. However without the dependencyCheck = true, the code compiles and at runtime, all dependencies are successfully injected and everything seems to work as intended. Preferably, I want to have dependencyCheck true so that I could catch unsatisfied dependency errors early. I am not sure if this is a spring quirk or I missed out something in my code. Following is my code
The configurable class
The class that instantiates Crawler outside of spring containerCode:@Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true) public class Crawler extends WebCrawler { @Autowired private ContentRepository contentRepository; }
the pom file configurationCode:protected <T extends WebCrawler> void start(final Class<T> _c, final int numberOfCrawlers) { for (int i = 1; i <= numberOfCrawlers; i++) { T crawler = _c.newInstance(); // --> this is where the Crawler class instantiated outside of spring Thread thread = new Thread(crawler, "Crawler " + i); crawler.setThread(thread); crawler.init(i, this); thread.start(); crawlers.add(crawler); threads.add(thread); logger.info("Crawler " + i + " started."); } }
Please let me know what is going on and how do I get dependencyCheck to work? Thank you very muchCode:<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerVersion>1.6</compilerVersion> <fork>true</fork> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <complianceLevel>1.6</complianceLevel> <encoding>UTF-8</encoding> <aspectLibraries> <aspectLibrary> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </aspectLibrary> </aspectLibraries> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>test-compile</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <version>2.9</version> <configuration> <ajdtVersion>1.6.12</ajdtVersion> </configuration> </plugin> </plugins> </build>
P.S: Spring is really automagical. It has automagically revived my enthusiasm to program in Java


Reply With Quote
