Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pe.dao;
- @Component
- public class UserServicesDao {
- private DBConfiguration dbConfiguration;
- @Autowired()
- public void setDbConfiguration(DBConfiguration dbConfiguration) {
- this.dbConfiguration = dbConfiguration;
- }
- public List<User> getUser()
- {
- System.out.println("User Services Dao : "+this.toString());
- System.out.println("Connection Info : "+this.dbConfiguration);
- return new ArrayList<User>();
- }
- @Override
- public String toString() {
- return "UserServicesDao [connection Config=" + dbConfiguration + "]";
- }
- }
- package com.pe.bean;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.stereotype.Component;
- @Component(value ="dbConfiguration")
- public class DBConfiguration {
- @Value("com.mysql.jdbc.Driver")
- private String driver;
- @Value("jdbc:mysql://localhost:3306/mydb")
- private String url;
- @Value("root")
- private String username;
- @Value("root")
- private String password;
- public String getDriver() {
- return driver;
- }
- public void setDriver(String driver) {
- this.driver = driver;
- }
- public String getUrl() {
- return url;
- }
- public void setUrl(String url) {
- this.url = url;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
- <context:component-scan base-package="com.pe.controller,com.pe.dao,com.pe.bean" />
- <mvc:annotation-driven/>
- <bean id="viewResolver"
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix">
- <value>/jsp/</value>
- </property>
- <property name="suffix" value=".jsp">
- </property>
- </bean>
- <mvc:resources mapping="/resources/**" location="/resources/" />
- </beans>
- <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
- http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <servlet-name>spring</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/spring-servlet.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>spring</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <resource-ref>
- <description>DB Connection</description>
- <res-ref-name>jdbc/spring</res-ref-name>
- <res-type>javax.sql.DataSource</res-type>
- <res-auth>Container</res-auth>
- </resource-ref>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:com/predictenergy/bean/dao-config.xml</param-value>
- </context-param>
- </web-app>
- <bean id ="userServicesDao" class="com.pe.dao.UserServicesDao" autowire="byType">
- <property name="dbConfiguration" ref= "dbConfiguration"></property>
- </bean>
- <bean id ="dbConfiguration" class ="com.pe.bean.DBConfiguration">
- <property name="driver" value= "com.mysql.jdbc.Driver"></property>
- <property name="url" value= "jdbc:mysql://localhost:3306/mydb"></property>
- <property name="username" value= "root"></property>
- <property name="password" value= "root"></property>
- </bean>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement