Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring框架和重写默认bean_Java_Spring - Fatal编程技术网

Java Spring框架和重写默认bean

Java Spring框架和重写默认bean,java,spring,Java,Spring,我们有一个构建在spring之上的框架,我们希望让开发人员能够覆盖我们的默认bean。因此,在我们的“自定义主题器”的例子中,(我希望我们没有自定义主题器),我们有一个接口,可以自动连接到主题bean中 我们如何才能给用户实现相同接口的能力,并且我们将该bean自动连接到我们的themer类中,而不是默认的。假设接口是call NLSER,而我们的默认实现是NLSERConcrete,那么最终用户/开发人员如何才能注入CustomerLSER呢?使用XML中的注释或primary=“true”b

我们有一个构建在spring之上的框架,我们希望让开发人员能够覆盖我们的默认bean。因此,在我们的“自定义主题器”的例子中,(我希望我们没有自定义主题器),我们有一个接口,可以自动连接到主题bean中

我们如何才能给用户实现相同接口的能力,并且我们将该bean自动连接到我们的themer类中,而不是默认的。假设接口是call NLSER,而我们的默认实现是NLSERConcrete,那么最终用户/开发人员如何才能注入CustomerLSER呢?

使用XML中的注释或
primary=“true”
bean属性。这是您的默认bean:

@Service
public class NLSERConcrete implements NLSER {//...

//...in different class
@Autowired
private NLSER nlser;
现在,如果开发人员添加:

@Service
@Primary
public class CustomerNLSER implements NLSER {//...
对于类路径,Spring会选择它,在自动连接过程中,它将是首选