Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. package com.pe.dao;
  2.  
  3. @Component
  4. public class UserServicesDao {
  5.  
  6. private DBConfiguration dbConfiguration;
  7.  
  8.  
  9. @Autowired()
  10. public void setDbConfiguration(DBConfiguration dbConfiguration) {
  11. this.dbConfiguration = dbConfiguration;
  12. }
  13.  
  14. public List<User> getUser()
  15. {
  16. System.out.println("User Services Dao : "+this.toString());
  17. System.out.println("Connection Info : "+this.dbConfiguration);
  18.  
  19. return new ArrayList<User>();
  20.  
  21. }
  22.  
  23. @Override
  24. public String toString() {
  25. return "UserServicesDao [connection Config=" + dbConfiguration + "]";
  26. }
  27.  
  28. }
  29.  
  30. package com.pe.bean;
  31.  
  32. import org.springframework.beans.factory.annotation.Value;
  33. import org.springframework.context.annotation.ComponentScan;
  34. import org.springframework.stereotype.Component;
  35.  
  36.  
  37. @Component(value ="dbConfiguration")
  38.  
  39. public class DBConfiguration {
  40.  
  41. @Value("com.mysql.jdbc.Driver")
  42. private String driver;
  43.  
  44. @Value("jdbc:mysql://localhost:3306/mydb")
  45. private String url;
  46.  
  47. @Value("root")
  48. private String username;
  49.  
  50. @Value("root")
  51. private String password;
  52.  
  53. public String getDriver() {
  54. return driver;
  55. }
  56. public void setDriver(String driver) {
  57. this.driver = driver;
  58. }
  59. public String getUrl() {
  60. return url;
  61. }
  62. public void setUrl(String url) {
  63. this.url = url;
  64. }
  65. public String getUsername() {
  66. return username;
  67. }
  68. public void setUsername(String username) {
  69. this.username = username;
  70. }
  71. public String getPassword() {
  72. return password;
  73. }
  74. public void setPassword(String password) {
  75. this.password = password;
  76. }
  77. }
  78.  
  79. <?xml version="1.0" encoding="UTF-8"?>
  80.  
  81. <beans xmlns="http://www.springframework.org/schema/beans"
  82. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  83. xmlns:context="http://www.springframework.org/schema/context"
  84. xmlns:mvc="http://www.springframework.org/schema/mvc"
  85. xmlns:aop="http://www.springframework.org/schema/aop"
  86. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  87. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  88. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  89. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
  90.  
  91. <context:component-scan base-package="com.pe.controller,com.pe.dao,com.pe.bean" />
  92. <mvc:annotation-driven/>
  93.  
  94. <bean id="viewResolver"
  95. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  96. <property name="prefix">
  97. <value>/jsp/</value>
  98. </property>
  99. <property name="suffix" value=".jsp">
  100. </property>
  101. </bean>
  102. <mvc:resources mapping="/resources/**" location="/resources/" />
  103.  
  104. </beans>
  105.  
  106. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  107. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  108. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  109. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  110.  
  111. <welcome-file-list>
  112. <welcome-file>index.jsp</welcome-file>
  113. </welcome-file-list>
  114.  
  115.  
  116. <servlet>
  117. <servlet-name>spring</servlet-name>
  118. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  119. <init-param>
  120. <param-name>contextConfigLocation</param-name>
  121. <param-value>/WEB-INF/spring-servlet.xml</param-value>
  122. </init-param>
  123. <load-on-startup>1</load-on-startup>
  124. </servlet>
  125.  
  126. <servlet-mapping>
  127. <servlet-name>spring</servlet-name>
  128. <url-pattern>/</url-pattern>
  129. </servlet-mapping>
  130.  
  131. <resource-ref>
  132. <description>DB Connection</description>
  133. <res-ref-name>jdbc/spring</res-ref-name>
  134. <res-type>javax.sql.DataSource</res-type>
  135. <res-auth>Container</res-auth>
  136. </resource-ref>
  137.  
  138. <listener>
  139. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  140. </listener>
  141.  
  142.  
  143. <context-param>
  144.  
  145. <param-name>contextConfigLocation</param-name>
  146. <param-value>classpath:com/predictenergy/bean/dao-config.xml</param-value>
  147.  
  148. </context-param>
  149. </web-app>
  150.  
  151. <bean id ="userServicesDao" class="com.pe.dao.UserServicesDao" autowire="byType">
  152. <property name="dbConfiguration" ref= "dbConfiguration"></property>
  153. </bean>
  154.  
  155. <bean id ="dbConfiguration" class ="com.pe.bean.DBConfiguration">
  156. <property name="driver" value= "com.mysql.jdbc.Driver"></property>
  157. <property name="url" value= "jdbc:mysql://localhost:3306/mydb"></property>
  158. <property name="username" value= "root"></property>
  159. <property name="password" value= "root"></property>
  160.  
  161. </bean>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement