我正在将一个活跃的Spring Web应用程序迁移到spring boot(1.4.2).
bean在使用@ImportResource加载时在XML中定义.
我开始的4个bean是同一个对象BasicDataSource的一个实例.
要告诉spring哪个加载我已经为每个设置了一个ID并使用@Qualifier将正确的bean绑定到变量.
但似乎Spring忽略了我的@Qualifier并抛出"没有类型'javax.sql.DataSource'的限定bean可用:预期单个匹配bean但找到4:DataSource1,DataSource2,DataSource3,DataSource4"
PS - 请注意,具有@Qualifier的类是抽象类,而未能实例化的类是扩展类,但@Qualifier具有@Inherited.
XML
<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:jee="http://www.springframework.org/schema/jee" xmlns:task="http://www.springframework.org/schema/task"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
<context:load-time-weaver aspectj-weaving="on"/>
<cache:annotation-driven mode="aspectj"/>
<context:property-override location="file:/app/config/dataSourceOverride.cfg"/>
<context:annotation-config />
<bean id="DataSource1" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="userId" value="4" />
</bean>
<bean id="DataSource2" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="userId" value="3" />
</bean>
<bean id="DataSource3" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="userId" value="2" />
</bean>
<bean id="DataSource4" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="userId" value="1" />
</bean> …Run Code Online (Sandbox Code Playgroud) 实际上真是太棒了.有人可以用简单的英语解释为什么下面的部分工作与否?
class Hey;
class Bitmap {
public:
const Hey* const& getHey() { return hey; }; // works
const Hey* & getHey2() { return hey; }; // error C2440: 'return' : cannot convert from 'Hey *' to 'const Hey *&'
private:
Hey* hey;
};
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试制作一个CUDA代码,其中一个类将仅用于设备端(即主机不需要知道它的存在).但是我无法计算出类的正确限定符(deviceclass如下):
__device__ float devicefunction (float *x) {return x[0]+x[1];}
class deviceclass {
private:
float _a;
public:
deviceclass(float *x) {_a = devicefunction(x);}
float getvalue () {return _a;}
};
// Device code
__global__ void VecInit(float* A, int N)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < N) {
deviceclass *test;
test = new deviceclass(1.0, 2.0);
A[i] = test->getvalue();
}
}
// Standard CUDA guff below: Variables
float *h_A, *d_A;
// Host code
int main(int argc, char** argv) …Run Code Online (Sandbox Code Playgroud) 我在这个网址上阅读一些文字:
https://cs.senecac.on.ca/~btp100/pages/content/varia_p.html
在"资格赛"一节中,他们说:
"我们可以限定int类型以确保它包含最小位数"......一个short包含至少16位:....
我不明白这一点,"限定int类型"是什么意思以及为什么"一个短包含至少16位".
有人可以详细说明吗?谢谢大家.
我正在尝试更改我的应用程序图标,使其与Honeycomb的蓝色相匹配,但保留以前Android版本的绿色图标.我遇到了一个问题,如果我将蓝色72x72图标放在drawable-xlarge中,它会在启动器中正确使用它,但它也会将其用于ActionBar.72x72非常大,它超越了ActionBar的顶部和底部.
我的res目录如下:
drawable - images for ldpi & mdpi screens (48x48)
drawable-hdpi - for hdpi screens (72x72)
drawable-xlarge - just images for tablets
如何正确组织蓝色图标,以便72x72用于启动器,48x48用于ActionBar?
Spring有自己的Qualifier注释,我认为它等同于javax.inject.Named注释,而注释又是JSR-330中的具体限定符.
那么,我想知道Spring的哪个版本(如果有的话)支持Qualifier?
这是我的示例用法,遗憾的是它不适用于spring-context 3.0.5:
@Retention(RUNTIME)
@javax.inject.Qualifier
public @interface Version {
String value();
}
@Configuration
public class MyConfig {
@Bean("book-12") @Version("a") Book book12a() { ... }
@Bean("book-12") @Version("b") Book book12b() { ... }
}
@Component
public class UserClass {
@Inject @Named("book-12") Book anybook12;
@Inject @Named("book-12") @Version("b") Book book12_b;
}
Run Code Online (Sandbox Code Playgroud) 我有这个错误:
BSPArduino.cpp:316:错误:将'const BSPArduino'作为'this'参数传递给'virtual void BSPArduino :: enableWdt(const WATCHDOG_TIMER_DELAY&,const ___ bool&)'丢弃限定符
这个方法定义如下:
void BSPArduino::enableWdt(const WATCHDOG_TIMER_DELAY &delay, const ___bool &enable)
Run Code Online (Sandbox Code Playgroud)
我想这样称呼它:
enableWdt(this->watchdogTimer, ___false);
Run Code Online (Sandbox Code Playgroud)
附:
WATCHDOG_TIMER_DELAY watchdogTimer;
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这个构建错误...
非常感谢你的帮助
安东尼
我正在使用内置unordered_map<Node*, unordered_set<Edge>>数据结构的c ++编写DiGraph(有向图)类,其中Node和Edge是我自己定义的两个结构。在课堂上,我编写了一种containsNode()方法来搜索图中是否存在a Node。这是containsNode()方法主体:
bool DiGraph::containsNode(const Node * n) const {
auto::const_iterator it = digraph.find(n);
return (it == digraph.end());
}
Run Code Online (Sandbox Code Playgroud)
digraph是DiGraph类型的私有成员unordered_map<Node*, unordered_set<Edge>>。
但是,编译器生成以下错误:
error: no matching member function for call to 'find'
auto::const_iterator it = digraph.find(n);
candidate function not viable: 1st argument ('const Node *') would lose const qualifier
const_iterator find(const key_type& __k) const {return __t...
Run Code Online (Sandbox Code Playgroud)
但是,如果我将方法声明为
bool DiGraph::containsNode(Node* n) const {...}(唯一的区别是const从参数列表中删除了关键字),则没有编译错误。
我检查了C ++文档,发现容器中的find()方法声明unordered_map …
给定以下类型:
struct A
{
std::vector<std::string> vec;
using reference = std::iterator_traits<decltype(vec)::iterator>::reference;
using const_reference = const reference;
};
Run Code Online (Sandbox Code Playgroud)
为什么reference == const_reference?为什么const限定符会在第二个类型别名中删除?
请参阅godbold上不应编译的示例.
我有一个模板化的类,它将一堆迭代器(-types)作为模板参数.从这些迭代器我需要推导出引用和const引用类型,因为我有一些成员函数,如:
struct A
{
std::vector<std::string> vec;
using reference = std::iterator_traits<decltype(vec)::iterator>::reference;
using const_reference = const reference;
const_reference foo() const
{
return vec[0];
}
};
Run Code Online (Sandbox Code Playgroud)
通过删除const限定符,我实际上返回了一个foo非法的引用,因为它是一个const成员函数,所以编译器抛出.
我正在尝试为一组担任过政治职务的人(爱丁堡大学校友)返回结果。我想返回所担任职位的标题标签,以及每个职位的开始和结束日期,许多人担任多个职位。如果这个人只担任一个职位,我似乎能够找到其中一个,或者可以让它发挥作用,但无法让两者走到一起,因为有多个办公室。
我当前的查询版本如下。这将为我提供开始和结束日期,但如果政治办公室(例如英国 [x] 议会成员)将返回标签,而不是标签, ?officeLabel 返回一个值,例如:statement/Q4668868-E3734C7D-40F0-4D4A-8208-E3D6B8C944CB
SELECT DISTINCT ?alumni ?fullName ?roleLabel ?officeLabel ?start ?end WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?alumni wdt:P69 wd:Q160302.
?alumni rdfs:label ?fullName.
?alumni wdt:P106 ?role.
#Use Values to separate out politicians - Q82955
VALUES (?role) {
(wd:Q82955)
}
#Select only where position of office is stated but make dates optional
?alumni p:P39 ?office.
OPTIONAL { ?office pq:P580 ?start. }
OPTIONAL { ?office pq:P582 ?end. }
FILTER(LANGMATCHES(LANG(?fullName), "en"))
FILTER(NOT EXISTS { FILTER(LANGMATCHES(LANG(?fullName), "en-ca")) …Run Code Online (Sandbox Code Playgroud) qualifiers ×10
c++ ×5
java ×2
spring ×2
android ×1
autowired ×1
c ×1
c++17 ×1
class ×1
const ×1
cuda ×1
device ×1
icons ×1
jsr330 ×1
properties ×1
resources ×1
return-type ×1
scope ×1
sparql ×1
spring-boot ×1
visual-c++ ×1
wikidata ×1