Tag: datasource

React-Native更新列表视图数据源

我有一个iOS应用程序,我正在与反原生。 Game类包含一个ListView组件。 我在构造函数中设置状态并包含一个dataSource 。 我现在有一个硬编码的数据数组,我存储在不同的状态属性( this.state.ds )。 然后在componentDidMount我使用cloneWithRows方法将我的this.state.ds克隆为视图的dataSource。 就ListViews而言,这是非常标准的,并且运行良好。 这里是代码: /** * Sample React Native App * https://github.com/facebook/react-native */ 'use strict'; var React = require('react-native'); var { StyleSheet, Text, View, ListView, TouchableHighlight } = React; class Games extends React.Component{ constructor(props){ super(props); var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 != r2 }); this.state […]

应该在server.xml还是context.xml中设置数据库连接属性

我正在尝试使用JNDI为Spring Web应用程序设置数据库连接属性。 我正在考虑两种方法如下: 方法1: 在你的Springconfiguration中你可能有这样的东西: <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/facs"/> 然后在你的webapp /META-INF/context.xml文件中,你也应该有类似的东西: <?xml version='1.0' encoding='utf-8'?> <!– antiResourceLocking="true" –> <Context path="/podd-apn" reloadable="true" cachingAllowed="false" antiResourceLocking="true" > <Resource name="jdbc/facs" type="javax.sql.DataSource" username="${database.username}" password="${database.password}" driverClassName="org.postgresql.Driver" url="${database.url}" maxActive="8" maxIdle="4" global="jdbc/facs" /> </Context> 在你的web.xml中你应该像这样: <!– JNDI –> <resource-ref> <description>FACs Datasource</description> <res-ref-name>jdbc/facs</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> 方法2: 像这样在Spring环境中设置: <jee:jndi-lookup id="dbDataSource" jndi-name="jdbc/DatabaseName" expected-type="javax.sql.DataSource" /> 你可以使用类似下面的方法在Tomcat的server.xml中声明JNDI资源: <GlobalNamingResources> <Resource […]

dynamic更改Spring数据源

我有一个Spring应用程序,我想dynamic地更改数据源,即。 当input一个DS URL时,Spring bean和所有的依赖关系会自动更新。我知道这有些奇怪,但无论如何,我想实现这一点。 我的Springconfiguration如下: <bean id="majorDataSource" class="org.postgresql.ds.PGSimpleDataSource"> <property name="serverName" value="${jdbc.serverName}" /> <property name="portNumber" value="${jdbc.portNumber}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="databaseName" value="${jdbc.databaseName}" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="majorDataSource"/> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="majorDataSource"/> <property name="configLocation" value="classpath:sqlmap-config.xml"/> </bean> 问题是: JDBC URL存储在属性中,可以更改运行时。 一旦URL被更改,我需要重新创build数据源,也许依赖对象。 我不知道如何在spring优雅地做到这一点? 我知道Spring可以根据一个键dynamic地路由数据源,但是数据源URL是在Spring中预定义的,不会改变运行时。 这不是我的情况。

如何在Spring中使用由Tomcat提供的JNDI数据源?

在Spring的javadoc文章中有关于DriverManagerDataSource类的说法,这个类很简单,推荐使用 使用容器提供的JNDI数据源。 这样的DataSource可以通过JndiObjectFactoryBean在Spring ApplicationContext中作为DataSource bean公开 问题是:如何做到这一点? 例如,如果我希望有DataSource bean来访问我的custo mysql数据库,那么我需要什么? 在上下文configuration等写什么?