constructorargument

How do I perform Constructor-based dependency injection with Spring using annotations?

血红的双手。 提交于 2020-01-04 01:53:08
问题 OK, so if I need to put some primitive values in the constructor, how do I do that? @Autowired public CustomBean(String name, @Qualifier("SuperBean") SuperBean superBean) { super(); this.superBean = superBean; this.name = name; } For instance here I am defining that the superBean has the Qualifier "SuperBean", but I'd also like to know how is it possible to use annotations to set the name value here? I know it's possible with xml configuration, but I want to know how to do this with

map Comparison Constructor Parameter

若如初见. 提交于 2019-12-12 03:02:40
问题 Is there a reason why I cannot pass a comparison functor to a map as a constructor argument: map<int, string, greater<int>> foo; //map<int, string> foo(greater<int>()); Doesn't work Or why I cannot pass a lambda without providing my own comparison type: map<int, string, function<bool(const int&, const int&)>> bar([](const int& lhs, const int& rhs){ return lhs > rhs; }); //map<int, string> bar([](const int& lhs, const int& rhs){ return lhs > rhs; }); Doesn't work I'd like to just be able to