I'm trying to use @Autowired annotation with my generic DAO interface:
Public Interface DaoContainer & lt; E domain object & gt; {Public entity numberIf items ();
I use my controller in this function in the following functions:
@ Configurable public class HelloWald {@Autowired Private DaoContainer & lt; Notification & gt; NotificationContainer; @ Owned Private Documents Container & lt; Users & gt; UserContainer; // Execution Execution}
I have configured my configuration with the configuration
& lt; Context: spring-configure / & gt; & Lt; Reference: component-scan base-package = "com.organization.Sample" & gt; & Lt; Context: Out-filter expression = "org.springframework.stereotype.Controller" type = "annotation" /> & Lt; / Reference: Component Scan & gt; & Lt; Tx: annotation-driven / & gt;
This only works partially, because Spring makes only one example of my Dow Container, i.e. Dow Container, and in other words, if I use userContainer.numberOfItems ( ) Ask; I get a notification number. Container.Number Off Items ()
I have tried to use the strongly typed interface to mark the correct implementation:
Public Interface Notification Editor DaoContainer Expands & lt; Notification & gt; {} Public Interface Extends UserContainer DaoContainer & lt; Users & gt; {}
And then these interfaces have been used in this way:
@ Configurable public class HelloWorld {@Autowired Private Notification Dialogers Notification; @ Authorized User YouTube Container User Container; // Execution Expedition ...}
Unfortunately this bean fails in the frozen exception:
org.springframework.beans.factory.BeanCreationException : Could not autowire field: private com.organization.sample.dao.NotificationContainer com.organization.sample.HelloWorld.notificationContainer; Nested exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean type [com.organization.sample.NotificationContainer] found for dependency: at least 1 bean is expected which qualifies as autowire candidate for this dependency is. Dependency Annotation: {@ org.springframework.beans.factory.annotation.Autowired (required = true)}
Now, I'm a bit confused about how I should proceed or multiple Dao's It is also possible that any help would be greatly appreciated :)
OK It seems that I have found a fairly reasonable solution for this puzzle. One way of dealing with this is to understand the interface and implementation of each unit in my domain model. Will Rman (as ESPN foretold in his response). Now, think about implementing hundreds of institutions and respectively. It will not look right, is not it?
I have abandoned the typed sub-interface and I am using the normal interface instead:
@Service // @ Aspen public class HelloWald {@Autowired Private DaoContainer & lt; Notification & gt; NotificationContainer; @ Owned Private Documents Container & lt; Users & gt; UserContainer; // execution left}
The implementation for my Dow Container interface will look something like this:
@ Repository public class DaoContainerImpl & lt; E extends DomainObject & gt; Daocontentear & lt; E & gt; Applies {// it is classified in my application logic & lt; E & gt; type;
And finally the application reference:
& lt; Context: Public int getNumberOfItems () {// Exclude implementation} // left setters for getters and fields}
Spring Configure /> & Lt; Reference: component-scan base-package = "com.organization.Sample" & gt; & Lt; Context: Out-filter expression = "org.springframework.stereotype.Controller" type = "annotation" /> & Lt; / Reference: Component Scan & gt; & Lt; Bean class = "com.organization.sample.dao.DaoContainerImpl" id = "userContainer" & gt; & Lt; Property Name = "Type" value = "com.organization.sample.domain.DiaryUser" /> & Lt; / Bean & gt; & Lt; Bean class = "com.organization.sample.dao.DaoContainerImpl" id = "notificationcontainer" & gt; & Lt; Property Name = "Type" value = "com.organization.sample.domain.DiaryNotification" /> & Lt; / Bean & gt;
So basically I could not do pure generic automation to work, but this solution works for me (at least still) :)
Comments
Post a Comment