You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/13 09:59:34 UTC

[GitHub] [shardingsphere] tony1991 opened a new issue #6336: how to get DataSource by DataSourceName

tony1991 opened a new issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336


   ## Question
   
   how to get DataSource by DataSourceName in my application?I want to get a specific DataSource from dataSourceMap, but there is no function to get dataSourceMap or DataSource. Looking forward for your reply


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] kimmking commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
kimmking commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657595728


   Autowired is injected by type, so there are many ds instances, an error occurs.
   You should use `@Resource("ds1")`, injected by name.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] kimmking closed issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
kimmking closed issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657509185


   > There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   > For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   > So, where did you want to get dataSource?
   
   
   my config like this pic
   ![微信图片_20200713193730](https://user-images.githubusercontent.com/11584767/87300391-50a83080-c540-11ea-8e53-33037144ff81.jpg)
   
   I want get ds1 after ss init , can you give some examples?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657509185


   > There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   > For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   > So, where did you want to get dataSource?
   
   
   my config like this pic
   ![微信图片_20200713193730](https://user-images.githubusercontent.com/11584767/87300391-50a83080-c540-11ea-8e53-33037144ff81.jpg)
   
   I want to get ds1 after shardingjdbc init , can you give some examples?
   
   And if I inject ds1 like follow, my codes compiled fail.
   
   @Autowired
   private DataSource ds1;
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 removed a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 removed a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658173599






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] kimmking edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
kimmking edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657595728


   `@Autowired` is injected by type, so there are many ds instances, an error occurs.
   You should use `@Resource("ds1")`, injected by name.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658180045


   > @tony1991 simple way
   > 
   > ` ShardingSphereDataSource dataSource = (ShardingSphereDataSource)applicationContext.getBean(DataSource.class); Map<String, DataSource> dataSourceMap = dataSource.getDataSourceMap();`
   > 
   > or you can @autowire datasource
   
   Good! I have try before submit issues. But I have not convert DataSource to ShardingDataSource, so I can't get dataSourceMap. Your method works well! Thank you!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] kimmking commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
kimmking commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657488468


   There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   So, where did you want to get dataSource?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658173599


   > dataSourceMap
   
   dataSourceMap is final private and there is no method like `dataSource.getDataSourceMap();`
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] kimmking commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
kimmking commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658095426


   > > `@Autowired` is injected by type, so there are many ds instances, an error occurs.
   > > You should use `@Resource("ds1")`, injected by name.
   > 
   > it's still not work. My shardingjdbc version is 4.0.0-RC2.
   > 
   > ![微信图片_20200714131203](https://user-images.githubusercontent.com/11584767/87386730-bb567c00-c5d3-11ea-8467-77925ca6a9b1.jpg)
   
   ds1 is the bean name in spring context, if your resource is null, something else is wrong.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657509185


   > There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   > For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   > So, where did you want to get dataSource?
   
   
   my config like this pic
   ![微信图片_20200713193730](https://user-images.githubusercontent.com/11584767/87300391-50a83080-c540-11ea-8e53-33037144ff81.jpg)
   
   I want get ds1 after shardingjdbc init , can you give some examples?
   
   And if I inject ds1 like follow, my codes complied fail.
   
   @Autowired
   private DataSource ds1;
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658177419


   > DataSource
   
   
   
   > ds1 is the bean name in spring context, if your resource is null, something else is wrong.
   
   I know and I can get ShardingDataSource by `@Autowire datasource`.  I have read the source code.
   The ShardingDataSource cantains more dataSources in a dataSourceMap, but I can't get  these dataSources. you can try it.
   I suggest you can change dataSourceMap to public or provide a public method to invoke


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657509185


   > There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   > For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   > So, where did you want to get dataSource?
   
   
   my config like this pic
   ![微信图片_20200713193730](https://user-images.githubusercontent.com/11584767/87300391-50a83080-c540-11ea-8e53-33037144ff81.jpg)
   
   I want get ds1 , can you give some examples?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657509185


   > There are many different ways for retrieving DataSource by its name, according to where your codes are weaving in ss.
   > For example, in spring/spring-boot env, you can inject bean by name. Sometimes we can get ds from SchemaContext-ShardingSphereSchema-dataSources Map.
   > So, where did you want to get dataSource?
   
   
   my config like this pic
   ![微信图片_20200713193730](https://user-images.githubusercontent.com/11584767/87300391-50a83080-c540-11ea-8e53-33037144ff81.jpg)
   
   I want get ds1 after ss init , can you give some examples?
   
   And if I inject ds1 like follow, my codes complied fail.
   
   @Autowired
   private DataSource ds1;
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657970185


   > `@Autowired` is injected by type, so there are many ds instances, an error occurs.
   > You should use `@Resource("ds1")`, injected by name.
   
   it's still not work.
   ![微信图片_20200714131203](https://user-images.githubusercontent.com/11584767/87386730-bb567c00-c5d3-11ea-8467-77925ca6a9b1.jpg)
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657970185


   > `@Autowired` is injected by type, so there are many ds instances, an error occurs.
   > You should use `@Resource("ds1")`, injected by name.
   
   it's still not work. My shardingjdbc version is 4.0.0-RC2.
   
   ![微信图片_20200714131203](https://user-images.githubusercontent.com/11584767/87386730-bb567c00-c5d3-11ea-8467-77925ca6a9b1.jpg)
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] xbkaishui commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
xbkaishui commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658554645


   no problem, you can close this issue if it is ok. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-657970185


   > `@Autowired` is injected by type, so there are many ds instances, an error occurs.
   > You should use `@Resource("ds1")`, injected by name.
   
   it's still not work.
   ![微信图片_20200714131018](https://user-images.githubusercontent.com/11584767/87386588-6f0b3c00-c5d3-11ea-9301-d9b53671425e.jpg)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] tony1991 edited a comment on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
tony1991 edited a comment on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658177419


   > DataSource
   
   
   
   > ds1 is the bean name in spring context, if your resource is null, something else is wrong.
   
   I know and I can get ShardingDataSource by `@Autowire datasource`.  I have read the source code.
   The ShardingDataSource cantains more dataSources in a dataSourceMap, but I can't get  these dataSources. you can try it.
   Maybe you can change dataSourceMap to public or provide a public method to invoke


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] xbkaishui commented on issue #6336: how to get DataSource by DataSourceName

Posted by GitBox <gi...@apache.org>.
xbkaishui commented on issue #6336:
URL: https://github.com/apache/shardingsphere/issues/6336#issuecomment-658031969


   @tony1991 simple way 
   
   `     ShardingSphereDataSource dataSource = (ShardingSphereDataSource)applicationContext.getBean(DataSource.class);
     Map<String, DataSource> dataSourceMap =  dataSource.getDataSourceMap();
   `
   
   or you can @autowire datasource 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org