Announcement Announcement Module
Collapse
No announcement yet.
Autowiring with factory-methods? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Help! I have similar problem but do not know how to fix

    I am new to JAVA programming and I am trying to create a portlet in Eclipse using Maven, Hibernate and Springframe. I get the same type of error message (see below) when I try to deploy my portlet to LIFERAY. I am confused by what I have done wrong. Can anyone PLEASE help me? Here is the error message and some of my code/situation:

    13:13:23,543 ERROR [ContextLoader:215] Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'projectTasksPortlet': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private edu.fccc.psf.projecttasks.services.TimeAcctService
    edu.fccc.psf.projecttasks.portlet.ProjectTasksPort let.timeAcctService; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'timeAcctService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private edu.fccc.psf.projecttasks.dao.ProjectsUsersDao edu.fccc.psf.projecttasks.services.TimeAcctService .projectsUsersDao; nested exception is org.springframework.beans. factory.NoSuchBeanDefinitionException: No unique bean of type [edu.fccc.psf.projecttasks.dao.ProjectsUsersDao] is defined: Unsatisfied dependency of type [interface edu.fccc.psf.projecttasks.dao.ProjectsUsersDao]: expected at least 1 matching bean

    I created my data access objects (I believe the term I was told is DAO/TO). I then created my services "TimeAcctService" which accesses one of my DAOs using

    @Service
    @Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
    public class TimeAcctService {

    @Autowired
    private ProjectsUsersDao projectsUsersDao;

    @Transactional(propagation = Propagation.REQUIRED)
    public void saveProjectsUsers(ProjectsUsers projectsUsers) {
    projectsUsersDao.saveProjectsUsers(projectsUsers);
    }

    @Transactional(propagation = Propagation.REQUIRED, readOnly=false)
    public void deleteProjectsUsers(ProjectsUsers projectsUsers) {
    projectsUsersDao.deleteProjectsUsers(projectsUsers );
    }


    @Transactional(propagation = Propagation.REQUIRED)
    public List getProjectsUsers (String username) {
    return projectsUsersDao.getProjectsUsers(username);
    }

    public ProjectsUsers getProjectsUsers (Integer record) {
    return projectsUsersDao.getProjectsUsers(record);
    }
    }

    Why does the @Autowired fail. Is the problem in one of my configuartion files or have I done something else wrong? PLEASE help me.

    Comment


    • #17
      Originally posted by Marten Deinum View Post
      The type is determined by return type of the factory method NOT based on the object returned from the factory-method itself.

      It is done to prevent over eagerly instantiation of beans and to prevent heavy objects from beeing instantiated. (Imagine some object which takes about 10 secs to create and it nog being a singleton, it would be quite a burden for startup).
      Thanks again for clarifying.

      Is there a way to tell spring which class/interfaces objects returned by factory-method implement? This means overwriting the default reflection mechanism? Something like


      ____________________
      watch movies online

      Comment


      • #18
        Sorry I don't understand your reply. I have my getters and setters for my DAO. Why do I keep getting the following error message:

        18:19:02,744 ERROR [ContextLoader:215] Context initialization failed
        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'timeAcctService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: private edu.fccc.psf.projecttasks.dao.ProjectsUsersDao edu.fccc.psf.projecttasks.services.TimeAcctService .projectsUsersDao; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'projectsUsersDao' defined in ServletContext resource [/WEB-INF/portlet-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'dataSource' of bean class [edu.fccc.psf.projecttasks.dao.ProjectsUsersHiberna teDao]: Bean property 'dataSource' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

        Comment


        • #19
          This is a nice solution

          Basically use ReflectionTestUtils

          http://hillert.blogspot.com/2008/04/...ing-25-to.html

          Comment

          Working...
          X