我们有一个按日期划分数据的系统.因此,例如在SqlServer中,我们每月有一个数据库.每个月分区使用包含在C3P0连接池DataSource中的Jdbc驱动程序数据源.
经过一段时间后,分区的日期范围变得足够大,我们想要使其脱机.在这种情况下,我们只从可用列表中删除相关月份的DataSource.但是,理想情况下,当离线时我想"关闭"DataSource,以便池放弃所有与DB的连接.
DataSource没有密切的方法让我打电话所以我不知道如何清理它.
有什么建议?
我在Windows窗体应用程序中使用CheckBoxList,并尝试为其应用数据源.
有一个DataTable,"DT",以列id,name并且ischecked,我用这样的代码:
((ListBox)MyCheckBoxList).DataSource = dt;
((ListBox)MyCheckBoxList).DisplayMember = "name";
((ListBox)MyCheckBoxList).ValueMember = "id";
Run Code Online (Sandbox Code Playgroud)
如何为MyCheckBoxList中的所有项设置CheckState?
我将此值保留在我的数据表中,并希望将它们与MyCheckBoxList链接.
根据这篇文章,您可以使用Spring Framework中的AbstractRoutingDataSource动态更改应用程序使用的数据源.
但是,使用的数据源是由配置定义的,而不是以编程方式定义的.有没有办法配置要在运行时使用的数据源?
该解决方案的可扩展性如何,即数据源数量有何限制?
谢谢!
我在JBoss 7中部署的Java EE应用程序中使用PostgreSQL 9.1 JDBC4驱动程序(postgresql-9.1-902.jdbc4.jar).
我可以假设javax.sql.DataSource是线程安全的,这样多个线程可以同时调用它上面的getConnection()方法吗?
环境:
数据源:
productsDataSource = new kendo.data.DataSource({
type: "odata",
transport: {
read: "http://www.mydomain.com/odata.svc/products",
dataType: "json",
contentType: "application/json"
}
schema: {
type: "json",
data: function(data){
return data.value;
},
total: function(data){
return data['odata.count'];
},
model: product
},
pageSize: 50,
serverPaging: true,
serverFiltering: true,
serverSorting: true
});
Run Code Online (Sandbox Code Playgroud)获取数据:
productsDataSource.filter([{field:"Id",operator:"eq",value:5}]); //这将发送一个httprequest
productsDataSource.fetch(function(e){tempDataStorage = e.items; //处理数据的更多逻辑;});
问题:
在尝试在独立的tomcat(7)实例上部署和启动Spring启动应用程序时,我们遇到了一个问题,即找不到自动配置的spring数据源bean并抛出相应的异常:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [javax.sql.DataSource] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1060) at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:920) at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:815) at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 84 more
Run Code Online (Sandbox Code Playgroud)
简单的jdbc spring.datasource在application.properties中正确配置,并且应用程序本身与嵌入式tomcat实例完美地运行,作为独立的spring引导应用程序.
看起来好像无法正确读取和/或处理application.properties文件,或者在数据源自动配置完成之前触发了一些其他bean(例如REST控制器中的服务)的注入.
不使用嵌入式tomcat时是否需要任何额外配置?或者有没有人遇到过类似的问题?
简单的应用和配置:
@EnableAutoConfiguration
@Configuration
@ComponentScan("com.foo")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driverClassName=com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)
数据源使用示例:
@Repository …Run Code Online (Sandbox Code Playgroud) 我正在尝试动态创建GridView.其中一列是创建行的用户.
JobDebrief jd = new JobDebrief(JobID);
Job jb = new Job(JobID);
DataGrid db = JobClass.Job_Piece.BuildGrid();
db.Columns.Add(CreateBoundColumn(jd.DbriefedByUser, "User"));
PlaceHolder.Controls.Add(db);
db.DataSource = jb.Pieces;
db.DataBind();
Run Code Online (Sandbox Code Playgroud)
我在job_piece类中的BuildGrid函数中创建了GridView.
public static DataGrid BuildGrid()
{
DataGrid NewDg = new DataGrid();
NewDg.DataKeyField = "ID";
NewDg.AutoGenerateColumns = false;
NewDg.CssClass = "tblResults";
NewDg.HeaderStyle.CssClass = "tblResultsHeader";
NewDg.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
NewDg.ItemStyle.CssClass = "ResultsStyle";
NewDg.Columns.Add(Load.CreateBoundColumn("AdvisedQty", "Qty Advised"));
NewDg.Columns.Add(Load.CreateBoundColumn("PieceTypeString", "Piece Type"));
NewDg.Columns.Add(Load.CreateBoundColumn("ReceivedQty", "Rcvd Qty"));
NewDg.Width = Unit.Percentage(100.00);
return NewDg;
}
public static BoundColumn CreateBoundColumn(string DataField, string Header,string CssClass ="",bool Highlight = false)
{
BoundColumn …Run Code Online (Sandbox Code Playgroud) 我有我的Spring Boot 1.2.5.RELEASE服务,我想使用HikariCP数据源而不是默认的tomcat-jdbc.所以,根据这个Spring Boot Reference我明白我只需tomcat-jdbc要从类路径中排除并添加HikariCP.
所以这是我的pom.xml:
...
<dependencyManagement>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
</dependencies>
...
Run Code Online (Sandbox Code Playgroud)
maven依赖树:
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ myproject-user-manage-webservice ---
[INFO] com.mybusiness.myproject:myproject-user-manage-webservice:jar:0.0.1-SNAPSHOT
[INFO] +- com.mybusiness.myproject:myproject-commons:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- com.mybusiness.myproject:myproject-core:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- com.mybusiness.myproject:myproject-core-commons:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.mybusiness.myproject:myproject-api:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile (version managed …Run Code Online (Sandbox Code Playgroud) 为了创建应该在ASP.NET中使用的自定义数据源,我创建了一个自定义数据源类,一个自定义编辑器和一个自定义可序列化类.
我无法理解的是为什么它不起作用......即使我可能有更多的属性而不是必需的(我一直在浏览和尝试几个小时),从我的理解PersistenceMode(PersistenceMode.InnerProperty)应该做的诀窍......此外,在我看来,我的代码类似于为什么我不能在WebForm中声明UserControl的子元素(属性)?.
代码的工作原理如下:
[ParseChildren(true)]
[PersistChildren(true)]
public class MyDataSource : DataSourceControl
{
// [much more irrelevant code...]
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(Editors.ResultRequestEditor), typeof(System.Drawing.Design.UITypeEditor))]
public ResultRequest Request { get; set; }
}
[Serializable]
[PersistChildren(true)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[ParseChildren(true)]
public class ResultRequest
{
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public string ColumnName { get; set; }
[Browsable(true)]
[EditorBrowsable(EditorBrowsableState.Always)]
public Type ColumnType { get; set; }
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Always)]
public object[] ResultTypeParameters { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
自定义编辑器似乎工作:使用它后,VS中的属性正确更新.
但是,在更新某些内容后,信息不会保留在ASPX文件中:
<cc1:MyDataSource ID="SearchDataSource1" runat="server" ProviderID="MyProvider1" />
Run Code Online (Sandbox Code Playgroud)
我期望的是数据源中的一些序列化,例如: …
我正在开发一个带有数据库每个租户策略的spring boot多租户应用程序.要求是在运行时添加新数据库,这意味着我必须动态创建新的数据源对象.
我还查看了Spring的AbstractRoutingDataSource,但需要预先定义的数据源.所以我只想知道如何在不重启应用服务器的情况下添加/删除数据源.
提前致谢.
datasource ×10
java ×6
spring ×4
c# ×3
asp.net ×2
runtime ×2
spring-boot ×2
c3p0 ×1
checkboxlist ×1
controls ×1
database ×1
databound ×1
editor ×1
gridview ×1
hikaricp ×1
jdbc ×1
kendo-ui ×1
multi-tenant ×1
odata ×1
winforms ×1