项目1:
申请主:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws ServiceException {
SpringApplication.run(Application.class, args);
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class);
context.scan("se.group.system");
context.refresh();
项目2(这是作为jar导入到项目1中的项目)
配置类:
@Configuration
@EnableJpaRepositories("se.group.system.repository") //Heres where it goes wrong I think
@EnableJpaAuditing
@EnableTransactionManagement
@Profile("Production")
public class Config{
@Bean(name = "mysql")
public DataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("com.mysql.jdbc.Driver");
config.setJdbcUrl(databaseUrl);
config.setUsername(databaseUsername);
config.setPassword(databasePassword);
return new HikariDataSource(config);
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory factory) {
return new JpaTransactionManager(factory);
}
运行应用程序时的错误:
"描述:
se.group.system.service.FooService中构造函数的参数0需要一个类型为' se.group.system.repository.FooRepository'的bean。无法找到。
动作:
考虑定义一个类型为'se.group.system.repository.FooRepository'的bean。在您的配置中。"