/** * 获取新的数据源 * * @return */ public static DataSource getNewDataSource() { if (newDataSource == null) synchronized (TaleUtils.class) { if (newDataSource == null) { Properties properties = TaleUtils.getPropFromFile("application-default.properties"); if (properties.size() == 0) { return newDataSource; } DriverManagerDataSource managerDataSource = new DriverManagerDataSource(); managerDataSource.setDriverClassName("com.mysql.jdbc.Driver"); managerDataSource.setPassword(properties.getProperty("spring.datasource.password")); String str = "jdbc:mysql://" + properties.getProperty("spring.datasource.url") + "/" + properties.getProperty("spring.datasource.dbname") + "?useUnicode=true&characterEncoding=utf-8&useSSL=false"; managerDataSource.setUrl(str); managerDataSource.setUsername(properties.getProperty("spring.datasource.username")); newDataSource = managerDataSource; } } return newDataSource; }
@Setup public void setup() throws PropertyVetoException { dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(propertyOr("jdbcUrl", "jdbc:mysql://127.0.0.1:3306?useSSL=false")); dataSource.setUsername(propertyOr("username", "root")); dataSource.setPassword(propertyOr("password", "root")); JdbcTemplate delegate = new JdbcTemplate(dataSource); delegate.setDataSource(dataSource); proxy = new SenderProxy(new JdbcTemplateSender(delegate)); proxy.onMessages(updated -> counter.addAndGet(updated.size())); reporter = reporter(proxy); batch = new BatchJdbcTemplate(delegate, reporter); batch.setDataSource(dataSource); unbatch = new JdbcTemplate(dataSource); unbatch.setDataSource(dataSource); unbatch.update(CREATE_DATABASE); unbatch.update(DROP_TABLE); unbatch.update(CREATE_TABLE); }
@Bean @Override public DataSource selectAnyDataSource() { try { setProperties(); defaultDataSource = new DriverManagerDataSource(); defaultDataSource.setUrl(url); defaultDataSource.setUsername(username); defaultDataSource.setPassword(password); defaultDataSource.setDriverClassName(driver); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("select any :: base-multitenant-select-any"); return defaultDataSource; }
@Test public void testLocalSessionFactoryBeanWithCustomSessionFactory() throws Exception { final SessionFactory sessionFactory = mock(SessionFactory.class); LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() { @Override protected SessionFactory newSessionFactory(Configuration config) { return sessionFactory; } }; sfb.setMappingResources(new String[0]); sfb.setDataSource(new DriverManagerDataSource()); sfb.setExposeTransactionAwareSessionFactory(false); sfb.afterPropertiesSet(); assertTrue(sessionFactory == sfb.getObject()); sfb.destroy(); verify(sessionFactory).close(); }
@Test @SuppressWarnings("serial") public void testLocalSessionFactoryBeanWithNamingStrategy() throws Exception { LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() { @Override protected Configuration newConfiguration() { return new Configuration() { @Override public Configuration setNamingStrategy(NamingStrategy namingStrategy) { throw new IllegalArgumentException(namingStrategy.toString()); } }; } }; sfb.setMappingResources(new String[0]); sfb.setDataSource(new DriverManagerDataSource()); sfb.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); try { sfb.afterPropertiesSet(); fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException ex) { // expected assertTrue("Correct exception", ex.getMessage().equals(ImprovedNamingStrategy.INSTANCE.toString())); } }
@Before @Ignore public void setUp() { try { //TODO: should be rewritten. DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(Config.DRIVERCLASSNAME); dataSource.setUrl(Config.URL); dataSource.setUsername(Config.USERNAME); dataSource.setPassword(Config.PASSWORD); jdbc = new JdbcUserRepository(new JdbcTemplate(dataSource)); //TODO: run creating scripts. Assert.assertTrue(true); } catch (Throwable throwable) { Assert.fail(throwable.getMessage()); } }
@Before @Ignore public void setUp() { try { //TODO: should be rewritten. DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(Config.DRIVERCLASSNAME); dataSource.setUrl(Config.URL); dataSource.setUsername(Config.USERNAME); dataSource.setPassword(Config.PASSWORD); jdbc = new JdbcCommodityRepository(new JdbcTemplate(dataSource)); //TODO: run creating scripts. Assert.assertTrue(true); } catch (Throwable throwable) { Assert.fail(throwable.getMessage()); } }
@Bean(name = "rootDataSource") public DataSource rootDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName")); dataSource.setUrl(environment.getRequiredProperty("jdbc.root.url")); dataSource.setUsername(environment.getRequiredProperty("jdbc.root.username")); dataSource.setPassword(environment.getRequiredProperty("jdbc.root.password")); return dataSource; }
/** * Creates the data source from the settings map * * @param settingsMap - the settingMap containing the db connection settings * @return the DataSource object */ public static DataSource getDataSource(HashMap settingsMap) { String driver; if ("MySQL".equals(settingsMap.get("datasource.ojb.platform"))) { driver = "com.mysql.jdbc.Driver"; } else if ("Oracle9i".equals(settingsMap.get("datasource.ojb.platform"))) { driver = "oracle.jdbc.driver.OracleDriver"; } else { driver = (String) settingsMap.get("datasource.driver.name"); } DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(driver); dataSource.setUrl((String) settingsMap.get("datasource.url")); dataSource.setUsername((String) settingsMap.get("datasource.username")); dataSource.setPassword((String) settingsMap.get("datasource.password")); return dataSource; }
@RequestMapping(value = "/emailVerification", method = RequestMethod.GET) public ModelAndView emailVerificationProcess(HttpServletRequest request, Map<String, Object> model) { ModelAndView modelview = new ModelAndView(); String token = request.getParameter("token"); LeafUser user = UserUtil.getUserFromToken(token); if(user != null) { DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); // Inject the datasource into the dao JdbcUserDAO userDAO = new JdbcUserDAO(); userDAO.setDataSource(datasource); userDAO.updateUserStatus(user.getLid(), "1"); JdbcUtil.cleanUp(datasource); String msg = "<img src='images/leafsoft.png' alt='LeafSoft'><br><h3>Hi "+user.getUsername()+"</h3>,<br>"+"<h4>Welcome to LeafSoft!<br>Now that you've successfully created an LeafSoft Online account."; msg = msg + "<br><br>Thanks<br>The LeafSoft Team"; SendMail.send(user.getEmail(), "Welcome to LeafSoft", msg); modelview.addObject("msg","email verification done!!. Please Login"); } else { modelview.addObject("msg","can't verify your account. Please tryagain.."); } modelview.setViewName("login"); return modelview; }
@RequestMapping(value="/forgetPassword", method= RequestMethod.POST) public ModelAndView forgetPassword(@RequestParam("username") String username, Map<String, Object> model,HttpServletRequest request) { ModelAndView modelview = new ModelAndView(); LOGGER.log(Level.INFO,"Email::::"+username); DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); // Inject the datasource into the dao JdbcUserDAO userDAO = new JdbcUserDAO(); userDAO.setDataSource(datasource); LeafUser user = userDAO.loadUserByUsername(username); String token = UserUtil.getUserToken(user); String serverName = request.getServerName(); if(serverName.contains("localhost")) { serverName = serverName+":"+request.getServerPort()+(request.getServletContext().getContextPath()); } String verificationUrl = request.getScheme()+"://"+serverName+"/resetPassword?token="+token; LOGGER.log(Level.INFO,"Generated token"+token); String msg = "<img src='images/leafsoft.png' alt='LeafSoft'><br><h3>Hi "+user.getUsername()+"</h3>,<br>"+"<h4>Here is the link to reset your LeafSoft Account Password:"; msg = verificationUrl; msg = msg + "<br><br>Thanks<br>The LeafSoft Team"; SendMail.send(user.getEmail(), "Reset your LeafSoft account password", msg); SecurityContextHolder.clearContext(); modelview.setViewName("login"); modelview.addObject("msg", "Reset Password link has been send to your registered mail!"); return modelview; }
@RequestMapping(value="/resetPassword", method= RequestMethod.POST) public ModelAndView resetPassword(@RequestParam("token") String token, Map<String, Object> model,@RequestParam("password") String password,HttpServletRequest request) { ModelAndView modelview = new ModelAndView(); LeafUser user = UserUtil.getUserFromToken(token); String newpassword = new BCryptPasswordEncoder().encode(password); if(user != null) { DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); // Inject the datasource into the dao JdbcUserDAO userDAO = new JdbcUserDAO(); userDAO.setDataSource(datasource); userDAO.updateUserPassword(user.getLid(), newpassword); modelview.addObject("msg","ResetPassword successfully"); String msg = "<img src='images/leafsoft.png' alt='LeafSoft'><br><h3>Hi "+user.getUsername()+"</h3>,<br>"+"<h4>The password for your LeafSoft Account was recently changed.<br><br>"; msg = msg + "<br><br>Thanks<br>The LeafSoft Team"; SendMail.send(user.getEmail(), "Your password changed", msg); JdbcUtil.cleanUp(datasource); } else { modelview.addObject("error","can't reset your account. Please try again.."); } modelview.setViewName("login"); return modelview; }
public static LeafUser getCurrentUser() { LeafUser leafuser = null; User User = null; Authentication a = SecurityContextHolder.getContext().getAuthentication(); try{ if(a.getPrincipal() != null) { User = (User) a.getPrincipal(); } else { return null; } }catch(Exception e) { return null; } if(User!=null) { DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); JdbcUserDAO userDAO = new JdbcUserDAO(); userDAO.setDataSource(datasource); leafuser = userDAO.loadUserByUsername(User.getUsername()); } return leafuser; }
public static LeafUser getUserFromToken(String token) { //return new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseUserFromToken(token); Claims claims = new TokenHandler(DatatypeConverter.parseBase64Binary(AppResources.getInstance().getTokeSecret())).parseJWT(token); String claimsId = claims.getId(); DriverManagerDataSource datasource = new JdbcUtil().getAccountsDataSource(); // Inject the datasource into the dao JdbcUserDAO userDAO = new JdbcUserDAO(); userDAO.setDataSource(datasource); LeafUser user = userDAO.findByCustomerId(Integer.parseInt(claimsId)); if(user.getUsername().equals(claims.getIssuer()) && user.getEmail().equals(claims.getSubject())) { return user; } else { return null; } }
/** * Creates and returns a new data source from the given connection information. Creates a new {@link DriverManagerDataSource}. * * @param jdbcConnection the JDBC connection * @param variables the optional map of key-value for expression evaluation * * @return a new {@link DataSource} */ private DataSource createDataSource(JdbcConnection jdbcConnection, Map<String, Object> variables) { String url = evaluate(jdbcConnection.getUrl(), variables, "jdbc connection url"); String username = evaluate(jdbcConnection.getUsername(), variables, "jdbc connection username"); String password = evaluate(jdbcConnection.getPassword(), variables, "jdbc connection password"); validateUrl(url); DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(); driverManagerDataSource.setUrl(url); driverManagerDataSource.setUsername(username); driverManagerDataSource.setPassword(password); driverManagerDataSource.setDriverClassName(getDriverClassName(jdbcConnection.getDatabaseType())); return driverManagerDataSource; }
@Bean(name = "dataSource") public DataSource dataSource() { DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName(driverClassName); ds.setUrl(databaseUrl); Properties p = new Properties(); Map<String, String> datasourceProperties = mapPropertyNames("datasource", hibernateConfiguration()); p.putAll(datasourceProperties); ds.setConnectionProperties(p); if (!StringUtils.isEmpty(username)) { ds.setUsername(username); } if (!StringUtils.isEmpty(password)) { ds.setPassword(password); } return ds; }
@Bean public DataSource configureDataSource() { log.info("*************** Env Variables configureDataSource *************** "); String driver = System.getenv(EnviromentVariables.DATASOURCE_DRIVER_CLASS.getCode()); String url = System.getenv(EnviromentVariables.DATASOURCE_URL.getCode()); String username = System.getenv(EnviromentVariables.DATASOURCE_USERNAME.getCode()); String password = System.getenv(EnviromentVariables.DATASOURCE_PASSWORD.getCode()); log.info("dataSource.driverClassName: " + driver); log.info("dataSource.url: " + url); log.info("dataSource.username: " + username); log.info("dataSource.password: ***"); log.info("*************** END Env Variables configureDataSource *************** "); DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(driver); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }
/** * @param host * @param port * @param service * @param user * @param pw * @return * @throws Exception */ public DriverManagerDataSource getDataSource(String host, String port, String service, String user, String pw) throws Exception { // Override this method if your datasource is different try { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(JDBC_DRIVER); String url = String.format("jdbc:oracle:thin:@%s:%s:%s", host, port, service); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(pw); return dataSource; } catch (Exception e) { throw new Exception("Unable to get data source. Reason: " + e.getMessage()); } }
/** * Setup of test data: set attributes, purge and initialize test datbase */ @Before public void setup() throws SQLException, LiquibaseException { // Init jdbcTemplate this.jdbcTemplate = new JdbcTemplate(datasource); // Set test db properties DriverManagerDataSource ds = (DriverManagerDataSource)datasource; this.paasTestDbUrl = ds.getUrl(); this.paasTestDbUser = ds.getUsername(); this.paasTestDbPassword = ds.getPassword(); // purge test database liquibaseWrapper.purgeDatabase(paasTestDbUrl, paasTestDbUser, paasTestDbPassword); // init database state liquibaseWrapper.applyChangeLog(paasTestDbUrl, paasTestDbUser, paasTestDbPassword, basicInitialChangeLofFile); }
/** * 建立多個DriverManagerDataSource * * @return * @throws Exception */ protected DriverManagerDataSource[] createDriverManagerDataSources() throws Exception { DriverManagerDataSource[] result = null; try { int maxDataSourceSize = extendedProperties.getInt(MAX_DATA_SOURCE_SIZE, DEFAULT_MAX_DATA_SOURCE_SIZE); result = new DriverManagerDataSource[maxDataSourceSize]; // for (int i = 0; i < maxDataSourceSize; i++) { DriverManagerDataSource dataSource = createDriverManagerDataSource(i); result[i] = dataSource; } } catch (Exception e) { LOGGER.error(new StringBuilder("Exception encountered during createDriverManagerDataSources()").toString(), e); try { result = (DriverManagerDataSource[]) shutdownDriverManagerDataSources(); } catch (Exception sie) { throw sie; } throw e; } return result; }
/** * 關閉 * * @return */ protected DriverManagerDataSource[] shutdownDriverManagerDataSources() throws Exception { try { if (this.driverManagerDataSources != null) { for (int i = 0; i < this.driverManagerDataSources.length; i++) { DriverManagerDataSource oldInstance = this.driverManagerDataSources[i]; // oldInstance.close(); this.driverManagerDataSources[i] = null; } // this.driverManagerDataSources = null; } } catch (Exception e) { LOGGER.error( new StringBuilder("Exception encountered during shutdownDriverManagerDataSources()").toString(), e); throw e; } return this.driverManagerDataSources; }
@Before public void setup() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME); dataSource.setUrl(DATASOURCE_URL); dataSource.setUsername(DATASOURCE_USER_NAME); dataSource.setPassword(DATASOURCE_USER_PASSWORD); this.dataSource = dataSource; try { this.server = Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)) .start(); } catch (SQLException e) { throw new IllegalStateException(e); } }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setUrl("jdbc:mysql://localhost:3306/ensaiospring"); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); Properties props = new Properties(); props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); props.setProperty("hibernate.show_sql", "true"); props.setProperty("hibernate.hbm2ddl.auto", "update"); factory.setJpaVendorAdapter(jpaVendorAdapter); factory.setDataSource(dataSource); factory.setJpaProperties(props); factory.setPackagesToScan("br.com.ciaware.springmvc.ensaio.models"); return factory; }
/** * 获得一个可用的池 * * @param ds * @param profile * @param max 当Max==0时等同于Nopool * @return */ public static IUserManagedPool getPool(DataSource ds, int min,int max,TransactionMode txMode) { if(txMode==TransactionMode.JDBC || txMode==TransactionMode.JTA){ max=0; } if(min==0){ min = JefConfiguration.getInt(DbCfg.DB_CONNECTION_POOL, 3); } IUserManagedPool result; if (ds instanceof IRoutingDataSource) { IRoutingDataSource rds = (IRoutingDataSource) ds; result= new RoutingDummyConnectionPool(rds); } else if(ds instanceof DriverManagerDataSource||ds instanceof SimpleDataSource){ result= new SingleManagedConnectionPool(ds, min, max); } else{ result= new SingleDummyConnectionPool(ds); } return result.setTransactionMode(txMode); }
public void testParametersSetWithList() { TestRdbmsOperation operation = new TestRdbmsOperation(); DataSource ds = new DriverManagerDataSource(); operation.setDataSource(ds); operation.setSql("select * from mytable where one = ? and two = ?"); List l = new ArrayList(); l.add(new SqlParameter("one", Types.NUMERIC)); l.add(new SqlParameter("two", Types.VARCHAR)); operation.setParameters(new SqlParameter[] { new SqlParameter("one", Types.NUMERIC), new SqlParameter("two", Types.NUMERIC)}); operation.afterPropertiesSet(); try { operation.validateParameters(new Object[] {new Integer(1), new String("2")}); assertEquals(2, operation.getDeclaredParameters().size()); // OK } catch (InvalidDataAccessApiUsageException idaauex) { fail("Should have validated with parameters set using List: " + idaauex.getMessage()); } }
@Test public void conf() throws Exception { // 1. migrate String[] args = new String[4]; args[0] = "migrate"; args[1] = "--conf"; args[2] = BASE_PATH + File.separator + "content12.xml"; args[3] = BASE_PATH + File.separator + "MasterContent.xml"; new MigrateCommand().execute(new Input(args)); // 2. initialize db as persistence-jpa does DataSource dataSource = new DriverManagerDataSource("jdbc:h2:mem:syncopedb;DB_CLOSE_DELAY=-1", "sa", null); new ResourceDatabasePopulator(new ClassPathResource("/schema20.sql")).execute(dataSource); // 3. attempt to set initial content from the migrated MasterContent.xml SAXParserFactory factory = SAXParserFactory.newInstance(); try (InputStream in = new FileInputStream(args[3])) { SAXParser parser = factory.newSAXParser(); parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false)); } }
/** * @return Access to relational database system for local deployments */ @Bean(name = "spring-demo-db") public DataSource dataSource() { boolean isCloud = Arrays.asList(ctx.getEnvironment().getActiveProfiles()).contains("cloud"); if (isCloud) { String msg = "DataSource bean has not been auto-reconfigured." + " Without, the application cannot exist in the Cloud."; logger.error(msg); throw new RuntimeException(msg); } logger.info("DataSource instance about to be created"); DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName(env.getRequiredProperty("db.driver")); ds.setUrl(env.getRequiredProperty("db.url")); ds.setUsername(env.getRequiredProperty("db.username")); ds.setPassword(env.getRequiredProperty("db.password")); return ds; }
public List<Map> getSqlSearchResult(String db, String sql) { DataSourceManager dataSourceManager = (DataSourceManager) ObjectLocator .lookup("dataSourceManager", CmsPlugin.PLUGIN_ID); List<Map> rs = new ArrayList<Map>(); if (dataSourceManager != null) { try { DataSourceModel dsm = dataSourceManager.getDataSourceByName(db); DriverManagerDataSource dmd = new DriverManagerDataSource(); dmd.setDriverClassName(dsm.getDriverClassName()); dmd.setUrl(dsm.getUrl()); dmd.setUsername(dsm.getUserName()); dmd.setPassword(dsm.getPassword()); BaseDaoSupport baseDao = new BaseDaoSupport(); // 动态设置数据源 baseDao.setDataSource(dmd); baseDao.setUseDataSourceDialect(true); rs = baseDao.getDBMapObjectList(sql); } catch (Exception e) { e.printStackTrace(); } } return rs; }
public AbstractDaoTestCase(String testName) { super(testName); ApplicationContext springApplicationContext = new FileSystemXmlApplicationContext(SPRING_FILE_PATH); springBeanFactory = springApplicationContext; DriverManagerDataSource dmds = (DriverManagerDataSource)springBeanFactory.getBean("dataSource"); System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, dmds.getUrl()); System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, dmds.getUsername()); System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, dmds.getPassword()); }
/** * Get the parameters of a function as a map that contains the name of the parameter and its SQL type. * * @param dbName * @param functionName * @return Map containing the parameter name and type * @throws SQLException * @throws java.io.IOException */ public static Map<String, String> getFunctionParameterListAsMap(String dbName, String functionName, DriverManagerDataSource dataSource) throws Exception { Map<String, String> paramMap = new HashMap<String, String>(); String paramList = getFunctionParameterListAsString(dbName, functionName, dataSource); StringTokenizer tokenizeParamList = new StringTokenizer(paramList, ","); while (tokenizeParamList.hasMoreTokens()) { String param = tokenizeParamList.nextToken(); StringTokenizer tokenizeParamString = new StringTokenizer(param, " "); String direction = tokenizeParamString.nextToken(); String paramName = tokenizeParamString.nextToken(); String paramType = tokenizeParamString.nextToken(); if (paramType.contains("(")) { paramType = paramType.substring(0, paramType.indexOf("(")); } paramMap.put(paramName, paramType); } return paramMap; }
@Override protected void setUp() throws Exception { super.setUp(); DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(DRIVER); dataSource.setUrl(URL); dataSource.setUsername(USERNAME); dataSource.setPassword(PASSWORD); jdbcTemplate = new JdbcTemplate(dataSource); createTestSchema(); reader.setParameters(parameters); reader.validate(new ArrayList<String>()); }
private static void setupDriverManagerDataSource() throws NamingException{ SimpleNamingContextBuilder builder = SimpleNamingContextBuilder .emptyActivatedContextBuilder(); DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(System.getProperty("usciitg.db.driver")); dataSource.setUrl(System.getProperty("usciitg.db")); dataSource.setUsername(System.getProperty("usciitg.db.user")); dataSource.setPassword(System.getProperty("usciitg.db.password")); builder.bind(System.getProperty("usciitg.datasource"), dataSource); }
@Bean public DataSource mysqlDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(MYSQL_DRIVER_CLASS_NAME); dataSource.setUrl(MYSQL_URL); dataSource.setUsername(MYSQL_USER_NAME); dataSource.setPassword(MYSQL_USER_PASSWORD); return dataSource; }