Abstract Factory Method template not working with Spring MVC

I have a problem with abstract implementation of a Factory pattern on Spring. I use Spring 3 MVC and Hibernate 3, which works fine if I do not use the abstract factory method template. I'm not sure what I need to add to the controller in order to access the Factory Class (CategoryFactory).

Is there anything in the controller or bean initiative?

class SectionsController extends MultiActionController {
    /* Do I have to initiate the CategoryFactory here? */

    public ModelAndView secList() throws Exception {
        CategoryFactory.CategoryType type = CategoryFactory.CategoryType.valueOf("view");
        modelMap.addAttribute("sectionList", CategoryFactory.findCategory(type).list(id));
        return new ModelAndView("Form", modelMap);
    }
}

Factory Abstract

public abstract class Category {
    public abstract List list(int departId);
}

public class CategoryFactory {
    public enum CategoryType { firstclass, secondClass, ... }
    public static Category findCategory(CategoryType categoryType) {
        // Create type specific Category implementation
    }
}
+3
source share
1 answer

It will be: class SectionsController extends MultiActionController {

  private HibernateTemplate hibernateTemplate;

public void setSessionFactory(SessionFactory sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
} 

public ModelAndView secList() Exception {  CategoryFactory.CategoryType type = CategoryFactory.CategoryType.valueOf( "view" );    modelMap.addAttribute( "sectionList", CategoryFactory.findCategory().list(hibernateTemplate, ID);      ModelAndView ( "", modelMap);    }  }

0

Source: https://habr.com/ru/post/1788335/


All Articles