我们有一个基础JPA存储库类,以及我们在项目中使用的一些其他实用程序方法.在Spring Data JPA文档之后,我们创建了类并在配置类中使用@EnableJpaRepositories注释,如以下示例所示:
@Configuration
@EnableJpaRepositories(basePackageClasses = MyApplication.class,
repositoryBaseClass = MyJpaRepositoryImpl.class)
public class SpringDataJpaMyRepositoryConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
我们还设置了basePackageClasses属性,以便找到我们的存储库,因为配置类不在应用程序根包中.一切都按预期工作,所以到目前为止没有任何问题.
现在我们想创建一个spring boot starter,将存储库基类添加到我们的项目中,无需进一步配置,但我们不知道如何操作.如果我们使用EnableJpaRepositories注释创建一个AutoConfiguration类来设置repositoryBaseClass属性,那么在使用@SpringBootApplication注释的类下查找存储库的自动存储库查找策略将不再起作用.
我们不能使用basePackageClasses属性,因为我们不知道使用自动配置的项目的主类或包.
有没有办法做到这一点?也许通过在我们的自动配置中重新定义一些bean?
理想的方法是允许设置存储库基类而不必再次定义所有Spring Data JPA自动配置.
我有一个 Spring Boot 应用程序,使用 Thymeleaf 3 作为应用程序页面的模板引擎。我们使用spring-boot-starter-thymeleaf提供的默认配置,HTML Thymeleaf 模板位于src/main/resources/templates文件夹下。
现在我们想使用 Thymeleaf 来生成一些 javascript 文件,使用新的 javascript 模板模式。这些 javascript 模板可以位于同一个 HTML 模板文件夹或另一个文件夹中(例如:src/main/resources/jstemplates)。
我不知道是否有一种方法可以添加此配置而不更改spring-boot-starter-thymeleaf提供的默认配置中的任何内容,或者我必须为所有内容创建完整配置。
我尝试了使用以下配置的第一个选项,该选项适用于 javascript 模板,但 html 模板不再适用。
配置:
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter
implements ApplicationContextAware {
private static final String UTF8 = "UTF-8";
@Autowired
private SpringTemplateEngine templateEngine;
@Autowired
private ThymeleafProperties properties;
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean
public ThymeleafViewResolver javascriptThymeleafViewResolver() {
ThymeleafViewResolver resolver = …Run Code Online (Sandbox Code Playgroud)