Advertisement
Guest User

Untitled

a guest
May 19th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  5. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
  6. <context:annotation-config />
  7.  
  8.  
  9. <bean id="dataSource"
  10. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  11. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  12. <property name="url" value="jdbc:mysql://localhost:3306/test"/>
  13. <property name="username" value="root"/>
  14. <property name="password" value="root"/>
  15. </bean>
  16.  
  17. <bean id="sessionFactory"
  18. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  19. <property name="configLocation" value="WEB-INF/hibernate.cfg.xml"/>
  20. <property name="dataSource" ref="dataSource" />
  21. </bean>
  22.  
  23. <bean id="userDao" class="util.UserDaoImpl">
  24. <property name="sessionFactory" ref="sessionFactory" />
  25. </bean>
  26. <context:component-scan base-package="controllers"/>
  27.  
  28. <bean id="userService" class="service.UserServiceImpl">
  29. <property name="userDao" ref="userDao"/>
  30. </bean>
  31.  
  32. <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
  33.  
  34.  
  35.  
  36. </beans>
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. <!--
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58. xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
  59. xmlns:aop="http://www.springframework.org/schema/aop"
  60. xsi:schemaLocation="http://www.springframework.org/schema/beans
  61. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  62. http://www.springframework.org/schema/context
  63. http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
  64.  
  65. <context:component-scan base-package="controllers"/>
  66. <context:component-scan base-package="objects"/>
  67. <context:component-scan base-package="service"/>
  68. <context:component-scan base-package="util"/>&ndash;&gt;
  69. <context:annotation-config />
  70. &lt;!&ndash;Из-за отсутствия строки ниже была ошибка
  71. Could not autowire. No beans of 'UserService' type found.&ndash;&gt;
  72.  
  73.  
  74. <bean id="userDao" class="util.UserDaoImpl">
  75. <property name="sessionFactory" ref="sessionFactory" />
  76. </bean>
  77.  
  78. <bean id="userService" class="service.UserServiceImpl">
  79. <property name="userDao" ref="userDao"/>
  80. </bean>
  81.  
  82. <bean id="sessionFactory"
  83. class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  84. <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
  85. <property name="dataSource" ref="dataSource" />
  86. </bean>
  87.  
  88. <bean id="dataSource"
  89. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  90. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  91. <property name="url" value="jdbc:mysql://localhost:3306/test"/>
  92. <property name="username" value="root"/>
  93. <property name="password" value="root"/>
  94. </bean>
  95.  
  96.  
  97. <context:annotation-config />
  98.  
  99.  
  100.  
  101. <aop:config>
  102. <aop:pointcut id="myPointcut"
  103. expression="execution(* util.UserDaoImpl*.*(..))" />
  104. <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
  105. </aop:config>
  106.  
  107. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  108. <tx:attributes>
  109. <tx:method name="getUserById*" propagation="REQUIRED" read-only="true" />
  110. <tx:method name="getAllUsers*" propagation="REQUIRED" read-only="true" />
  111. <tx:method name="addUser*" propagation="REQUIRED" />
  112. <tx:method name="deleteUser*" propagation="REQUIRED" />
  113. <tx:method name="updateUser*" propagation="REQUIRED" />
  114. </tx:attributes>
  115. </tx:advice>
  116.  
  117. <bean id="transactionManager"
  118. class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  119. <property name="sessionFactory" ref="sessionFactory" />
  120. <property name="dataSource" ref="dataSource"/>
  121. </bean>
  122.  
  123.  
  124.  
  125.  
  126. </beans>-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement