简体   繁体   English

Maven依赖关系下载jar文件

[英]Maven dependency for downloading a jar file

I hope someone can give me some hints on this one, because google ain't helped me too much. 我希望有人能给我一些提示,因为谷歌对我没有太多帮助。 I want to download a jar from Artifactory, and run it from my java code, but I encounter some difficulties on this simple step. 我想从Artifactory下载一个jar,并从我的Java代码运行它,但是在这个简单的步骤上遇到了一些困难。

this is the maven dependency that I cannot make work 这是我无法工作的Maven依赖

With that dependency, Maven knows the groupId, artifactId and version of my java file. 有了这种依赖性,Maven知道了我的Java文件的groupId,artifactId和版本。 As for the Scope field, I saw that it can either be compile, provided, runtime, system or test. 至于“作用域”字段,我看到它可以被编译,提供,运行时,系统或测试。

That jar file represents another module, it's an application, which I want to handle from the code, I don't want any particular state for that file when I am building the project, I just want to download it, and to use it when I need it, but it has to be downloaded inside the current project. 该jar文件代表另一个模块,它是一个应用程序,我想从代码中处理它,在构建项目时,我不希望该文件有任何特定状态,我只想下载该文件,并在需要时使用它我需要它,但是必须在当前项目中下载它。 Right now, with that maven dependency, the jar file will be downloaded from Artifactory when I build the project, but in the end I get an error: 现在,有了该maven依赖关系,当我构建项目时,将从Artifactory下载jar文件,但最后我得到一个错误:

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userManagerImpl' for bean class [com.cgm.user.impl.UserManagerImpl] conflicts with existing, non-compatible bean definition of same name and class [com.cgm.authentication.impl.UserManagerImpl] 由以下原因导致:org.springframework.context.annotation.ConflictingBeanDefinitionException:注释为Bean类[com.cgm.user.impl.UserManagerImpl]指定的Bean名称'userManagerImpl'与相同名称和类[ com.cgm.authentication.impl.UserManagerImpl]

So, Spring doesn't know what to choose; 因此,Spring不知道该选择什么。 I think one solution will be to rename all the beans from the project, but I can't afford to do that. 我认为一种解决方案是重命名项目中的所有bean,但是我负担不起。

Any suggestions? 有什么建议么?

Thanks a lot! 非常感谢!

For what you indicate, the problem is because you have several bean of the same type. 对于您指出的问题,是因为您有几个相同类型的bean。

You can use @Qualifier along with @Autowired . 您可以将@Qualifier@Autowired一起使用。 In fact spring will ask you explicitly select the bean if ambiguous bean type are found, in which case you should provide the qualifier 实际上,如果发现模棱两可的bean类型,spring会询问您是否明确选择了bean,在这种情况下,您应该提供限定符

For Example in following case it is necessary provide a qualifier 例如在以下情况下,有必要提供一个限定词

 @Component
 @Qualifier("staff") 
 public Staff implements Person {}

 @Component
 @Qualifier("employee") 
 public Manager implements Person {}


 @Component
 public Payroll {

 private Person person;

  @Autowired
  public Payroll(@Qualifier("employee") Person person){
      this.person = person;
  }

}

Another alternative is to use the @Qualifier annotation in the class definition if it is part of your project. 如果它是项目的一部分,则另一种选择是在类定义中使用@Qualifier批注。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM