Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

java - Scanning Spring Data repositories by Spring Config?

I'm trying to use spring data and spring config together in a small standalone application.

...
  public static void main( String[] args )
  {        
    ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
    ... 
  }

1. My question is how can I discover the spring data repositories without using

<jpa:repositories base-package="foo.repositories" />

by spring config ?

2. If not, can I use 'ClassPathXmlApplicationContext' and 'AnnotationConfigApplicationContext' together somehow ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can now use the annotation @EnableJpaRepositories("some.root.package") .

For example:

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
@EnableJpaRepositories("some.root.package")
@ComponentScan(basePackages = { "maybe.another.root.package" })
public class SystemConfiguration {
    ...
}

(Spring Data's announcement)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...