0

我正在使用 Maven 完全基于 Java 配置开发两个基于 spring 的应用程序(Ex app1 和 app2),并且没有 XML 配置。通过 Maven -WAR 插件,我创建了 app2 的 Jar 引用,并使用mvn install:install file我将 app2 jar 与 app1 绑定。app2 - 它用于从数据源获取信息。

我已经在 app1 实现类中自动连接了 app2 服务,以获取@Service在 app2 应用程序中注释的详细信息。

我的第一个疑问是:

app1 和 app2 都有单独的 AppConfig.java 文件。是否可以简单地自动装配其中一个@ServiceJar 格式的文件,或者我需要将 App2 的 AppConfig java 文件定义或导入到 App1 的 AppConfig.jave 文件中。

我尝试使用简单的自动装配外部 JAR@Service类并以错误结束。

@Service请帮助我将外部 Jar 自动连接到实现类需要做些什么。

下面是我的 App1 存储库类

@Repository
public class VehicleRepository {   

    @Autowired  
    VehicleService vehicleservice;   

    public Map<String, item> getAllTypes(String type) {     

            Vehicke vehicle = vehicleservice.getAllVehicle(type);

            // handle response here...
        } catch (Exception ex) {

            // handle exception here
        } finally {

        }
        return vehicleDetails;
    }

}

VehicleService可在外部 Jar 中使用。

车辆服务类:

@Service
public class VehicleService {

    public VehicleService() {
    }

    @Autowired
    PortRepository portRepository;

    @Autowired
    MessageSource messageSource;


    public Vehicle getAllVehicles(String type) {
        List<Vehicle> cehicles = portRepository.getPorts();
        return vehicle;
    }
4

1 回答 1

1

让我们简单点。
您的 App1 依赖于 App2。
所以你使用@Import(App2Config.class) class App1Config {},就是这样。

顺便说一句,你可以使用父 pom.xml 和模块 app1 和 app2 来代替使用“ mvn install:install file ”的技巧,并在 pom.xml <dependencies> 部分中声明模块 app1 对模块 app2 的依赖关系。然后你运行' mvn install '来构建你的项目。
在此处查看示例:http: //books.sonatype.com/mvnex-book/reference/multimodule.html

于 2014-10-19T15:37:24.033 回答