-
Notifications
You must be signed in to change notification settings - Fork 54.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Code for Dependency Injection Article. * Added Java based configuration. Downloaded formatter.xml and reformatted all changed files. Manually changed tab into 4 spaces in XML configuration files. * BAEL-434 - Spring Roo project files generated by Spring Roo. No formatting applied. Added POM, java and resources folders.
- Loading branch information
Showing
114 changed files
with
15,965 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.baeldung; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* = RooApplication | ||
* | ||
* TODO Auto-generated class documentation | ||
* | ||
*/ | ||
@SpringBootApplication | ||
public class RooApplication { | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
SpringApplication.run(RooApplication.class, args); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
roo/src/main/java/com/baeldung/config/SpringDataJpaDetachableRepositoryConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.baeldung.config; | ||
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryConfiguration; | ||
|
||
/** | ||
* = SpringDataJpaDetachableRepositoryConfiguration | ||
TODO Auto-generated class documentation | ||
* | ||
*/ | ||
@RooJpaRepositoryConfiguration | ||
public class SpringDataJpaDetachableRepositoryConfiguration { | ||
} |
18 changes: 18 additions & 0 deletions
18
...config/SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration.aj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO. | ||
// You may push code into the target .java compilation unit if you wish to edit any member(s). | ||
|
||
package com.baeldung.config; | ||
|
||
import com.baeldung.RooApplication; | ||
import com.baeldung.config.SpringDataJpaDetachableRepositoryConfiguration; | ||
import io.springlets.data.jpa.repository.support.DetachableJpaRepositoryImpl; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
privileged aspect SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration { | ||
|
||
declare @type: SpringDataJpaDetachableRepositoryConfiguration: @Configuration; | ||
|
||
declare @type: SpringDataJpaDetachableRepositoryConfiguration: @EnableJpaRepositories(repositoryBaseClass = DetachableJpaRepositoryImpl.class, basePackageClasses = RooApplication.class); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
roo/src/main/java/com/baeldung/config/WebMvcConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.baeldung.config; | ||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooWebMvcConfiguration; | ||
import org.springframework.roo.addon.web.mvc.thymeleaf.annotations.RooWebMvcThymeleafUIConfiguration; | ||
|
||
/** | ||
* = WebMvcConfiguration | ||
TODO Auto-generated class documentation | ||
* | ||
*/ | ||
@RooWebMvcConfiguration(defaultLanguage = "en") | ||
@RooWebMvcThymeleafUIConfiguration | ||
public class WebMvcConfiguration { | ||
} |
110 changes: 110 additions & 0 deletions
110
roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_ThymeleafUIConfiguration.aj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO. | ||
// You may push code into the target .java compilation unit if you wish to edit any member(s). | ||
|
||
package com.baeldung.config; | ||
|
||
import com.baeldung.config.WebMvcConfiguration; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.context.annotation.Bean; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; | ||
import org.thymeleaf.spring4.view.ThymeleafViewResolver; | ||
import org.thymeleaf.templatemode.TemplateMode; | ||
|
||
privileged aspect WebMvcConfiguration_Roo_ThymeleafUIConfiguration { | ||
|
||
declare parents: WebMvcConfiguration implements ApplicationContextAware; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@Autowired | ||
private ThymeleafProperties WebMvcConfiguration.thymeleafProperties; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@Autowired | ||
private TemplateEngine WebMvcConfiguration.templateEngine; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
private ApplicationContext WebMvcConfiguration.applicationContext; | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return ThymeleafProperties | ||
*/ | ||
public ThymeleafProperties WebMvcConfiguration.getThymeleafProperties() { | ||
return thymeleafProperties; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return TemplateEngine | ||
*/ | ||
public TemplateEngine WebMvcConfiguration.getTemplateEngine() { | ||
return templateEngine; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return ApplicationContext | ||
*/ | ||
public ApplicationContext WebMvcConfiguration.getApplicationContext() { | ||
return applicationContext; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @param applicationContext | ||
*/ | ||
public void WebMvcConfiguration.setApplicationContext(ApplicationContext applicationContext) { | ||
this.applicationContext = applicationContext; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return ThymeleafViewResolver | ||
*/ | ||
@Bean | ||
public ThymeleafViewResolver WebMvcConfiguration.javascriptThymeleafViewResolver() { | ||
ThymeleafViewResolver resolver = new ThymeleafViewResolver(); | ||
resolver.setTemplateEngine(getTemplateEngine()); | ||
resolver.setCharacterEncoding("UTF-8"); | ||
resolver.setContentType("application/javascript"); | ||
resolver.setViewNames(new String[] {"*.js"}); | ||
resolver.setCache(getThymeleafProperties().isCache()); | ||
return resolver; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return SpringResourceTemplateResolver | ||
*/ | ||
@Bean | ||
public SpringResourceTemplateResolver WebMvcConfiguration.javascriptTemplateResolver() { | ||
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); | ||
resolver.setApplicationContext(getApplicationContext()); | ||
resolver.setPrefix("classpath:/templates/fragments/js/"); | ||
resolver.setTemplateMode(TemplateMode.JAVASCRIPT); | ||
resolver.setCharacterEncoding("UTF-8"); | ||
resolver.setCheckExistence(true); | ||
resolver.setCacheable(getThymeleafProperties().isCache()); | ||
return resolver; | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
roo/src/main/java/com/baeldung/config/WebMvcConfiguration_Roo_WebMvcConfiguration.aj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO. | ||
// You may push code into the target .java compilation unit if you wish to edit any member(s). | ||
|
||
package com.baeldung.config; | ||
|
||
import com.baeldung.config.WebMvcConfiguration; | ||
import io.tracee.binding.springmvc.TraceeInterceptor; | ||
import java.lang.Override; | ||
import java.util.Locale; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; | ||
import org.springframework.web.servlet.LocaleResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; | ||
import org.springframework.web.servlet.i18n.SessionLocaleResolver; | ||
|
||
privileged aspect WebMvcConfiguration_Roo_WebMvcConfiguration { | ||
|
||
declare parents: WebMvcConfiguration extends WebMvcConfigurerAdapter; | ||
|
||
declare @type: WebMvcConfiguration: @Configuration; | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return LocalValidatorFactoryBean | ||
*/ | ||
@Primary | ||
@Bean | ||
public LocalValidatorFactoryBean WebMvcConfiguration.validator() { | ||
return new LocalValidatorFactoryBean(); | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return LocaleResolver | ||
*/ | ||
@Bean | ||
public LocaleResolver WebMvcConfiguration.localeResolver() { | ||
SessionLocaleResolver localeResolver = new SessionLocaleResolver(); | ||
localeResolver.setDefaultLocale(new Locale("en")); | ||
return localeResolver; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @return LocaleChangeInterceptor | ||
*/ | ||
@Bean | ||
public LocaleChangeInterceptor WebMvcConfiguration.localeChangeInterceptor() { | ||
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); | ||
localeChangeInterceptor.setParamName("lang"); | ||
return localeChangeInterceptor; | ||
} | ||
|
||
/** | ||
* TODO Auto-generated method documentation | ||
* | ||
* @param registry | ||
*/ | ||
@Override | ||
public void WebMvcConfiguration.addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(localeChangeInterceptor()); | ||
registry.addInterceptor(new TraceeInterceptor()); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
roo/src/main/java/com/baeldung/config/jackson/DomainModelModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.baeldung.config.jackson; | ||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooDomainModelModule; | ||
|
||
/** | ||
* = DomainModelModule | ||
TODO Auto-generated class documentation | ||
* | ||
*/ | ||
@RooDomainModelModule | ||
public class DomainModelModule { | ||
} |
28 changes: 28 additions & 0 deletions
28
roo/src/main/java/com/baeldung/config/jackson/DomainModelModule_Roo_DomainModelModule.aj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO. | ||
// You may push code into the target .java compilation unit if you wish to edit any member(s). | ||
|
||
package com.baeldung.config.jackson; | ||
|
||
import com.baeldung.config.jackson.DomainModelModule; | ||
import com.baeldung.domain.Book; | ||
import com.baeldung.web.BookJsonMixin; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.springframework.boot.jackson.JsonComponent; | ||
|
||
privileged aspect DomainModelModule_Roo_DomainModelModule { | ||
|
||
declare parents: DomainModelModule extends SimpleModule; | ||
|
||
declare @type: DomainModelModule: @JsonComponent; | ||
|
||
/** | ||
* TODO Auto-generated constructor documentation | ||
* | ||
*/ | ||
public DomainModelModule.new() { | ||
// Mixin registration | ||
|
||
setMixInAnnotation(Book.class, BookJsonMixin.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.baeldung.domain; | ||
import org.springframework.roo.addon.javabean.annotations.RooEquals; | ||
import org.springframework.roo.addon.javabean.annotations.RooJavaBean; | ||
import org.springframework.roo.addon.javabean.annotations.RooToString; | ||
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Version; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* = Book | ||
TODO Auto-generated class documentation | ||
* | ||
*/ | ||
@RooJavaBean | ||
@RooToString | ||
@RooJpaEntity | ||
@RooEquals(isJpaEntity = true) | ||
public class Book { | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@Version | ||
private Integer version; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@NotNull | ||
private String title; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@NotNull | ||
private String author; | ||
|
||
/** | ||
* TODO Auto-generated attribute documentation | ||
* | ||
*/ | ||
@NotNull | ||
private String isbn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO. | ||
// You may push code into the target .java compilation unit if you wish to edit any member(s). | ||
|
||
package com.baeldung.domain; | ||
|
||
import com.baeldung.domain.Book; | ||
import java.util.Objects; | ||
|
||
privileged aspect Book_Roo_Equals { | ||
|
||
/** | ||
* This `equals` implementation is specific for JPA entities and uses | ||
* the entity identifier for it, following the article in | ||
* https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/ | ||
* | ||
* @param obj | ||
* @return Boolean | ||
*/ | ||
public boolean Book.equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
// instanceof is false if the instance is null | ||
if (!(obj instanceof Book)) { | ||
return false; | ||
} | ||
return getId() != null && Objects.equals(getId(), ((Book) obj).getId()); | ||
} | ||
|
||
/** | ||
* This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able | ||
* to identify the entity in collections after a new id is assigned to the entity, following the article in | ||
* https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/ | ||
* | ||
* @return Integer | ||
*/ | ||
public int Book.hashCode() { | ||
return 31; | ||
} | ||
|
||
} |
Oops, something went wrong.