Guest User

Untitled

a guest
Nov 1st, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns="http://www.springframework.org/schema/beans"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  8. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
  9.  
  10. <context:component-scan base-package="ru.milli"/>
  11. <mvc:annotation-driven/>
  12. </beans>
  13.  
  14. <?xml version="1.0" encoding="UTF-8"?>
  15. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16. xmlns="http://www.springframework.org/schema/beans"
  17. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  18.  
  19. <import resource="classpath:application-context.xml"/>
  20.  
  21. </beans>
  22.  
  23. <?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  25. xmlns:mvc="http://www.springframework.org/schema/mvc"
  26. xmlns="http://www.springframework.org/schema/beans"
  27. xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. http://www.springframework.org/schema/beans/spring-beans.xsd
  29. http://www.springframework.org/schema/mvc
  30. http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
  31.  
  32. <import resource="classpath:application-context.xml"/>
  33. <mvc:resources mapping="/resources/**" location="/resources/"/>
  34. </beans>
  35.  
  36. package ru.rusal.mishka.core;
  37.  
  38. import com.mchange.v2.c3p0.ComboPooledDataSource;
  39. import org.eclipse.persistence.jpa.PersistenceProvider;
  40. import org.springframework.beans.factory.annotation.Qualifier;
  41. import org.springframework.context.annotation.Bean;
  42. import org.springframework.context.annotation.Configuration;
  43. import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
  44. import org.springframework.orm.jpa.JpaTransactionManager;
  45. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  46.  
  47. import javax.persistence.EntityManagerFactory;
  48. import javax.persistence.ValidationMode;
  49. import javax.sql.DataSource;
  50. import java.beans.PropertyVetoException;
  51. import java.util.Properties;
  52.  
  53. @Configuration
  54.  
  55. public class ContextConfiguration {
  56.  
  57. @Bean
  58. public DataSource dataSource(
  59. @Qualifier("systemConfiguration") SystemConfiguration systemConfiguration
  60. ) throws PropertyVetoException {
  61. Properties props = new Properties();
  62. props.setProperty("user", systemConfiguration.getDBConfig().getUser());
  63. props.setProperty("password", systemConfiguration.getDBConfig().getPassword());
  64.  
  65. final ComboPooledDataSource dataSource = new ComboPooledDataSource();
  66. dataSource.setDriverClass("oracle.jdbc.OracleDriver");
  67. dataSource.setJdbcUrl("jdbc:oracle:thin:@localhost:1521:DB");
  68. dataSource.setInitialPoolSize(5);
  69. dataSource.setMaxPoolSize(20);
  70. dataSource.setProperties(props);
  71.  
  72. return dataSource;
  73. }
  74.  
  75. @Bean
  76. public LocalContainerEntityManagerFactoryBean entityManagerFactory(
  77. @Qualifier("dataSource") DataSource ds
  78. ) {
  79. LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
  80.  
  81. factoryBean.setPersistenceUnitName("MilliService");
  82. factoryBean.setDataSource(ds);
  83. factoryBean.setPersistenceProviderClass(PersistenceProvider.class);
  84. factoryBean.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
  85. factoryBean.setValidationMode(ValidationMode.NONE);
  86. factoryBean.setPackagesToScan("ru.milli.app.persistence");
  87. factoryBean.getJpaPropertyMap().put("eclipselink.weaving", Boolean.FALSE.toString());
  88. factoryBean.getJpaPropertyMap().put("eclipselink.allow-zero-id", Boolean.TRUE.toString());
  89.  
  90. return factoryBean;
  91. }
  92.  
  93. @Bean
  94. public JpaTransactionManager transactionManager(
  95. @Qualifier("entityManagerFactory") EntityManagerFactory factory
  96. ) throws PropertyVetoException {
  97. JpaTransactionManager manager = new JpaTransactionManager();
  98. manager.setEntityManagerFactory(factory);
  99. return manager;
  100. }
  101. }
  102.  
  103. <?xml version="1.0" encoding="UTF-8"?>
  104. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  105. version="2.4"
  106. xmlns="http://java.sun.com/xml/ns/j2ee"
  107. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  108. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  109.  
  110. <!-- Display name -->
  111. <display-name>mishka</display-name>
  112.  
  113. <listener>
  114. <listener-class>ru.milli.CleanupContextListener</listener-class>
  115. </listener>
  116.  
  117. <servlet>
  118. <servlet-name>webportal</servlet-name>
  119. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  120. </servlet>
  121.  
  122. <servlet>
  123. <servlet-name>rest</servlet-name>
  124. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  125. </servlet>
  126.  
  127. <servlet-mapping>
  128. <servlet-name>rest</servlet-name>
  129. <url-pattern>/rest/*</url-pattern>
  130. </servlet-mapping>
  131.  
  132. <servlet-mapping>
  133. <servlet-name>webportal</servlet-name>
  134. <url-pattern>*.html</url-pattern>
  135. </servlet-mapping>
  136.  
  137. <servlet-mapping>
  138. <servlet-name>webportal</servlet-name>
  139. <url-pattern>/image.jpeg</url-pattern>
  140. </servlet-mapping>
  141.  
  142. <error-page>
  143. <error-code>500</error-code>
  144. <location>/WEB-INF/jsp/error.jsp</location>
  145. </error-page>
  146.  
  147. <error-page>
  148. <error-code>404</error-code>
  149. <location>/error.html</location>
  150. </error-page>
  151.  
  152. <welcome-file-list>
  153. <welcome-file>/WEB-INF/jsp/start.jsp</welcome-file>
  154. </welcome-file-list>
  155.  
  156. <jsp-config>
  157. <taglib>
  158. <taglib-uri>http://www.springframework.org/tags</taglib-uri>
  159. <taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
  160. </taglib>
  161. <taglib>
  162. <taglib-uri>http://www.springframework.org/tags/form</taglib-uri>
  163. <taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
  164. </taglib>
  165. </jsp-config>
  166.  
  167. </web-app>
Add Comment
Please, Sign In to add comment