SSH integration Summary (xml and annotation), ssh integration xml Annotation

Source: Internet
Author: User

SSH integration Summary (xml and annotation), ssh integration xml Annotation
I have encountered many problems during SSH integration. I would like to make a summary for your reference only.1. Configure with XML:Ii. Configure with annotation + XML:

  • When the struts. xml file is configured, the class value of the action must be written into the full name of the Action class.
  • Configure applicationContext. xml:
    <! -- Configure dataSource and sessionFactory --> <! -- Annotation ing Class package scanner --> <property name = "packagesToScan" value = "com. ssh. entity"> </property> <! -- Enable annotation dependency and injection --> <context: annotation-config/> <context: component-scan base-package = "com. ssh"/>
    <! -- Enable annotation transaction --> <bean id = "transactionManager" class = "org. springframework. orm. hibernate4.HibernateTransactionManager "> <property name =" sessionFactory "ref =" sessionFactory "> </property> </bean> <tx: annotation-driven transaction-manager =" transactionManager "/>
  • Annotation class Configuration:
    @Controller
    @Scope("prototype")
    public class UserAction extends ActionSupport { @Resource private UserService userService;}
    @Service
    @Transactionalpublic class UserService { @Resource private UserDaoImpl userDao;}@Repository("userDao")
    public class UserDaoImpl implements UserDao{ @Resource private SessionFactory sessionFactory;}
    // If you inherit the HibernateDaoSupport method, you cannot directly inject SessionFactory @ Repositorypublic class UserDaoImpl extends HibernateDaoSupport implements UserDao {@ ResourcePublic voidSetSuperSessionFactory (SessionFactory sessionFactory ){Super. SetSessionFactory (sessionFactory );}}
Other questions:
  • Problem: During Multi-to-one ing, the proxy object of one party is obtained when multiple objects are obtained. An exception occurs when the view layer is called: org. hibernate. lazyInitializationException: cocould not initialize proxy-no Session, that is, the proxy object cannot be initialized.
  • Cause: a transaction is added at the service layer, and the session is closed when the transaction is committed.
  • Solution (three methods ):
The above is the basic process of SSH configuration. Due to the length of the Code, only a part of the code is provided, which should not affect normal viewing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.