[英]Combine 2 Spring boot application
Just following Spring Guides http://spring.io/guides#gs I took gs-rest-service
and gs-accessing-data-jpa
. 刚刚关注Spring Guides http://spring.io/guides#gs我接受了
gs-rest-service
和gs-accessing-data-jpa
。 Now I want to combine them in one application, and that is where like more understanding of new org.springframework.boot.SpringApplication
is needed. 现在我想将它们组合在一个应用程序中,这就像需要更多地了解新的
org.springframework.boot.SpringApplication
。
In gs-rest-service
config looks emazing, that is almost absent 在
gs-rest-service
配置看起来是电子邮件,几乎不存在
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
gs-accessing-data-jpa
is more like Spring XML JavaConfig based app. gs-accessing-data-jpa
更像是基于Spring XML JavaConfig的应用程序。
@Configuration
@EnableJpaRepositories
public class CopyOfApplication {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(H2).build();
}
// 2 other beans...
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
public static void main(String[] args) {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(CopyOfApplication.class);
CustomerRepository repository = context.getBean(CustomerRepository.class);
//...
}
}
How to combine them? 如何结合它们?
Does it mean that I need to re-write SpringApplication.run
now on more detailed level ? 这是否意味着我需要在更详细的级别上重写
SpringApplication.run
?
In the Spring Boot application simply add the dependencies from the JPA sample (the ones which you don't already have. 在Spring Boot应用程序中,只需添加JPA示例中的依赖项(您尚未拥有的依赖项)。
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:0.5.0.M7")
compile("org.springframework:spring-orm:4.0.0.RC1")
compile("org.springframework.data:spring-data-jpa:1.4.1.RELEASE")
compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
compile("com.h2database:h2:1.3.172")
testCompile("junit:junit:4.11")
}
or instead of this you could also use the spring boot starter project for Spring Data JPA. 或者代之以你也可以使用Spring Data JPA的spring boot starter项目 。 In that case the dependencies would look like the following.
在这种情况下,依赖关系将如下所示。
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:0.5.0.M7")
compile("org.springframework.boot:spring-boot-starter-data-jpa:0.5.0.M7")
compile("com.h2database:h2:1.3.172")
testCompile("junit:junit:4.11")
}
This will pull in all needed dependencies. 这将引入所有需要的依赖项。
Next copy the CustomerRepository
to the Spring Boot application. 接下来将
CustomerRepository
复制到Spring Boot应用程序。 That basically should be everything you need. 这基本上应该是你需要的一切。 Spring Boot auto-configure now detects Spring Data JPA and JPA and will bootstrap hibernate, spring data for you.
Spring Boot自动配置现在可以检测Spring Data JPA和JPA,并将为你启动hibernate,spring数据。
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
ApplicationContext context= SpringApplication.run(Application.class, args);
CustomerRepository repository = context.getBean(CustomerRepository.class);
//...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.