小编And*_*ate的帖子

FactoryBeans和Spring 3.0中基于注释的配置

Spring提供了FactoryBean允许对bean进行非平凡初始化的接口.该框架提供了许多工厂bean的实现,并且 - 当使用Spring的XML配置时 - 工厂bean很容易使用.

但是,在Spring 3.0中,我找不到一种令人满意的方法来使用带有基于注释的配置的工厂bean(néeJavaConfig).

显然,我可以手动实例化工厂bean并自己设置任何所需的属性,如下所示:

@Configuration
public class AppConfig {

...

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
        factory.setDataSource(dataSource());
        factory.setAnotherProperty(anotherProperty());

        return factory.getObject();
    }
Run Code Online (Sandbox Code Playgroud)

然而,如果这将无法FactoryBean实现任何Spring特有的回调接口,如InitializingBean,ApplicationContextAware,BeanClassLoaderAware,或@PostConstruct例如.我还需要通过调用来检查的FactoryBean,找出回调接口它实现了,那么实现这个功能我自己setApplicationContext,afterPropertiesSet()等等.

这对我来说感觉很尴尬和反过来:应用程序开发人员不应该实现IOC容器的回调.

有没有人知道使用Spring Annotation配置的FactoryBeans更好的解决方案?

java spring inversion-of-control spring-annotations

24
推荐指数
3
解决办法
4万
查看次数

UISearchDisplayController.displaysSearchBarInNavigationBar将搜索栏定位在窗口中间

我正在尝试使用displaysSearchBarInNavigationBariOS7 UISearchDisplayController类中的属性来显示导航栏中的搜索栏.

使用AppleAdvancedTableSearch示例作为基础,我已经将代码更改为禁用范围(导航栏中不允许)并设置displaysSearchBarInNavigationBar为true,就像这样.

- (void)viewDidLoad
{
   [super viewDidLoad];

   // create a mutable array to contain products for the search results table
   self.searchResults = [NSMutableArray arrayWithCapacity:[self.products count]];
   self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我得到的结果看起来像这样:

搜索条在错误的地方

搜索栏显示在屏幕中间而不是navigationItem中.

我究竟做错了什么?

PS:我不确定它是否相关,但self.searchDisplayController.navigationItem属性是nil.

objective-c ios ios7

13
推荐指数
1
解决办法
6032
查看次数

在Redis/Lua脚本中使用TYPE命令

我试图在Lua脚本中使用Redis TYPE命令(通过EVAL执行)

local key_type = redis.call("TYPE", key)
Run Code Online (Sandbox Code Playgroud)

据Redis的文档,这应返回的字符串"none","zset"等等.

但是返回值的类型是lua table.将值与字符串进行比较始终返回false.

我设法通过更改呼叫来解决问题

local key_type = redis.call("TYPE", key)["ok"]
Run Code Online (Sandbox Code Playgroud)

该值确实是一个字符串,并且在字符串比较命令中起作用.我担心这是我特定版本的Redis中的一个错误,当我升级时它将在未来版本中破坏.

有谁知道这是预期的行为,还是一个错误?

lua redis

9
推荐指数
1
解决办法
982
查看次数