My plan is having 1 code 2 different app. Only 1 app will connect to database and hava a transaction. I am having an error when starting my webapp in the application where it doesnt have any database , the only way is to exclude JPA dependencies. When starting the application , it throws an error
Parameter 2 of constructor in chat.ChatService required a bean of type 'chat.ChatLogRepository' that could not be found.
This is my spring boot application
@AllArgsConstructor
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class ApplicationDmz implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(chat.ApplicationDmz.class, args);
}
@Bean
RestOperations restOperationsDmz() {
return new RestTemplate();
}
}
This is my service calling the CRUDRepository
@AllArgsConstructor
@Component
public class ChatService {
@Getter
private SimpMessageSendingOperations template;
SimpUserRegistry userRegistry;
private ChatLogRepository chatLogRepository;
And this is my CRUDRepository
import org.springframework.data.repository.CrudRepository;
public interface ChatLogRepository extends CrudRepository<ChatLog, Long> {
}
I just want to fix the issue when starting my app with exclude JPA
Your test bet is to import your repository bean manually:
import org.springframework.context.annotation.Import;
@Import(ChatLogRepository.class)
This should go within a @Configuration
class or your @SpringBootApplication
class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.