没有xml的{bean

时间:2017-10-25 12:57:24

标签: spring mockito config

请帮我从xml中创建一个spring config jJava文件。在xml bean中写成:

   <bean id="SettingsControllerDS" class="org.mockito.Mockito" factory-method="mock">
        <constructor-arg value="javax.sql.DataSource" />
   </bean>

我尝试编写Java配置文件:

@Configuration
@ComponentScan(basePackages = {"XXXXXXXXXX"})
public class SpringBeanTestApplicationContext {

    @Bean(name = "SettingsControllerDS")
    public DataSource dataSource() { !!! ???????? !!!! }
}

1 个答案:

答案 0 :(得分:1)

以下配置类将生成DataSource的模拟实例:

@Configuration
public class SpringBeanTestApplicationContext {

    @Bean(name = "SettingsControllerDS")
    public DataSource dataSource() { 
        return Mockito.mock(DataSource.class); 
    }
}