Skip to content

Commit 42e49e3

Browse files
committed
Projeto do curso
1 parent b4ca8d7 commit 42e49e3

File tree

92 files changed

+42856
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+42856
-0
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.algaworks</groupId>
7+
<artifactId>brewer</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<packaging>war</packaging>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
15+
16+
<failOnMissingWebXml>false</failOnMissingWebXml>
17+
18+
<java.version>1.8</java.version>
19+
<maven-compiler-pluging.version>3.2</maven-compiler-pluging.version>
20+
<flyway-maven-plugin.version>4.0.2</flyway-maven-plugin.version>
21+
<mysql-connector-java.version>5.1.39</mysql-connector-java.version>
22+
23+
<!-- Spring MVC -->
24+
<spring-framework.version>4.3.0.RELEASE</spring-framework.version>
25+
26+
<!-- Servlet API -->
27+
<servlet.version>3.1.0</servlet.version>
28+
29+
<!-- Thymeleaf -->
30+
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
31+
32+
<!-- Bean Validation / Hibernate Validator -->
33+
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
34+
35+
<!-- Thymeleaf - Layout Dialect -->
36+
<thymeleaf-layout-dialect.version>2.0.0-SNAPSHOT</thymeleaf-layout-dialect.version>
37+
38+
<!-- Logging -->
39+
<log4j.version>2.6</log4j.version>
40+
<jcl-over-slf4j.version>1.7.21</jcl-over-slf4j.version>
41+
42+
<!-- JPA / Hibernate -->
43+
<hibernate.version>5.1.0.Final</hibernate.version>
44+
45+
<!-- Spring Data JPA -->
46+
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
47+
48+
<!-- Jackson - JSON -->
49+
<jackson-core.version>2.7.5</jackson-core.version>
50+
</properties>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<artifactId>maven-compiler-plugin</artifactId>
56+
<version>${maven-compiler-pluging.version}</version>
57+
<configuration>
58+
<source>${java.version}</source>
59+
<target>${java.version}</target>
60+
</configuration>
61+
</plugin>
62+
63+
<plugin>
64+
<groupId>org.flywaydb</groupId>
65+
<artifactId>flyway-maven-plugin</artifactId>
66+
<version>${flyway-maven-plugin.version}</version>
67+
<configuration>
68+
<driver>com.mysql.jdbc.Driver</driver>
69+
</configuration>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
74+
<dependencyManagement>
75+
<dependencies>
76+
<dependency>
77+
<groupId>org.springframework</groupId>
78+
<artifactId>spring-framework-bom</artifactId>
79+
<version>${spring-framework.version}</version>
80+
<type>pom</type>
81+
<scope>import</scope>
82+
</dependency>
83+
</dependencies>
84+
</dependencyManagement>
85+
86+
<dependencies>
87+
<!-- Spring MVC -->
88+
<dependency>
89+
<groupId>org.springframework</groupId>
90+
<artifactId>spring-webmvc</artifactId>
91+
<scope>compile</scope>
92+
<exclusions>
93+
<exclusion>
94+
<groupId>commons-logging</groupId>
95+
<artifactId>commons-logging</artifactId>
96+
</exclusion>
97+
</exclusions>
98+
</dependency>
99+
100+
<!-- Servlet API -->
101+
<dependency>
102+
<groupId>javax.servlet</groupId>
103+
<artifactId>javax.servlet-api</artifactId>
104+
<version>${servlet.version}</version>
105+
<scope>provided</scope>
106+
</dependency>
107+
108+
<!-- Thymeleaf -->
109+
<dependency>
110+
<groupId>org.thymeleaf</groupId>
111+
<artifactId>thymeleaf</artifactId>
112+
<version>${thymeleaf.version}</version>
113+
<scope>compile</scope>
114+
</dependency>
115+
116+
<dependency>
117+
<groupId>org.thymeleaf</groupId>
118+
<artifactId>thymeleaf-spring4</artifactId>
119+
<version>${thymeleaf.version}</version>
120+
<scope>compile</scope>
121+
</dependency>
122+
123+
<!-- Bean Validation / Hibernate Validator -->
124+
<dependency>
125+
<groupId>org.hibernate</groupId>
126+
<artifactId>hibernate-validator</artifactId>
127+
<version>${hibernate-validator.version}</version>
128+
<scope>compile</scope>
129+
</dependency>
130+
131+
<!-- Thymeleaf - Layout Dialect -->
132+
<dependency>
133+
<groupId>nz.net.ultraq.thymeleaf</groupId>
134+
<artifactId>thymeleaf-layout-dialect</artifactId>
135+
<version>${thymeleaf-layout-dialect.version}</version>
136+
</dependency>
137+
138+
<!-- Logging -->
139+
<dependency>
140+
<groupId>org.apache.logging.log4j</groupId>
141+
<artifactId>log4j-slf4j-impl</artifactId>
142+
<version>${log4j.version}</version>
143+
</dependency>
144+
<dependency>
145+
<groupId>org.apache.logging.log4j</groupId>
146+
<artifactId>log4j-api</artifactId>
147+
<version>${log4j.version}</version>
148+
</dependency>
149+
<dependency>
150+
<groupId>org.apache.logging.log4j</groupId>
151+
<artifactId>log4j-core</artifactId>
152+
<version>${log4j.version}</version>
153+
</dependency>
154+
<dependency>
155+
<groupId>org.slf4j</groupId>
156+
<artifactId>jcl-over-slf4j</artifactId>
157+
<version>${jcl-over-slf4j.version}</version>
158+
</dependency>
159+
160+
<!-- JPA / Hibernate -->
161+
<dependency>
162+
<groupId>org.hibernate</groupId>
163+
<artifactId>hibernate-entitymanager</artifactId>
164+
<version>${hibernate.version}</version>
165+
<scope>compile</scope>
166+
</dependency>
167+
168+
<!-- Hibernate - Java 8 support -->
169+
<dependency>
170+
<groupId>org.hibernate</groupId>
171+
<artifactId>hibernate-java8</artifactId>
172+
<version>${hibernate.version}</version>
173+
<scope>compile</scope>
174+
</dependency>
175+
176+
<!-- MySQL Driver -->
177+
<dependency>
178+
<groupId>mysql</groupId>
179+
<artifactId>mysql-connector-java</artifactId>
180+
<version>${mysql-connector-java.version}</version>
181+
<scope>provided</scope>
182+
</dependency>
183+
184+
<!-- Spring Data JPA -->
185+
<dependency>
186+
<groupId>org.springframework.data</groupId>
187+
<artifactId>spring-data-jpa</artifactId>
188+
<version>${spring-data-jpa.version}</version>
189+
</dependency>
190+
191+
<!-- Jackson - JSON -->
192+
<dependency>
193+
<groupId>com.fasterxml.jackson.core</groupId>
194+
<artifactId>jackson-databind</artifactId>
195+
<version>${jackson-core.version}</version>
196+
<scope>compile</scope>
197+
</dependency>
198+
199+
</dependencies>
200+
201+
<repositories>
202+
<repository>
203+
<id>sonatype-nexus-snapshots</id>
204+
<name>Sonatype Nexus Snapshots</name>
205+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
206+
<snapshots>
207+
<enabled>true</enabled>
208+
</snapshots>
209+
</repository>
210+
</repositories>
211+
212+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.algaworks.brewer.config;
2+
3+
import javax.persistence.EntityManagerFactory;
4+
import javax.sql.DataSource;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9+
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
10+
import org.springframework.orm.jpa.JpaTransactionManager;
11+
import org.springframework.orm.jpa.JpaVendorAdapter;
12+
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
13+
import org.springframework.orm.jpa.vendor.Database;
14+
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
15+
import org.springframework.transaction.PlatformTransactionManager;
16+
import org.springframework.transaction.annotation.EnableTransactionManagement;
17+
18+
import com.algaworks.brewer.model.Cerveja;
19+
import com.algaworks.brewer.repository.Cervejas;
20+
21+
@Configuration
22+
@EnableJpaRepositories(basePackageClasses = Cervejas.class, enableDefaultTransactions = false)
23+
@EnableTransactionManagement
24+
public class JPAConfig {
25+
26+
@Bean
27+
public DataSource dataSource() {
28+
JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
29+
dataSourceLookup.setResourceRef(true);
30+
return dataSourceLookup.getDataSource("jdbc/brewerDB");
31+
}
32+
33+
@Bean
34+
public JpaVendorAdapter jpaVendorAdapter() {
35+
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
36+
adapter.setDatabase(Database.MYSQL);
37+
adapter.setShowSql(false);
38+
adapter.setGenerateDdl(false);
39+
adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
40+
return adapter;
41+
}
42+
43+
@Bean
44+
public EntityManagerFactory entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
45+
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
46+
factory.setDataSource(dataSource);
47+
factory.setJpaVendorAdapter(jpaVendorAdapter);
48+
factory.setPackagesToScan(Cerveja.class.getPackage().getName());
49+
factory.afterPropertiesSet();
50+
return factory.getObject();
51+
}
52+
53+
@Bean
54+
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
55+
JpaTransactionManager transactionManager = new JpaTransactionManager();
56+
transactionManager.setEntityManagerFactory(entityManagerFactory);
57+
return transactionManager;
58+
}
59+
60+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.algaworks.brewer.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import com.algaworks.brewer.service.CadastroCervejaService;
8+
import com.algaworks.brewer.storage.FotoStorage;
9+
import com.algaworks.brewer.storage.local.FotoStorageLocal;
10+
11+
@Configuration
12+
@ComponentScan(basePackageClasses = CadastroCervejaService.class)
13+
public class ServiceConfig {
14+
15+
@Bean
16+
public FotoStorage fotoStorage() {
17+
return new FotoStorageLocal();
18+
}
19+
20+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.algaworks.brewer.config;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Locale;
5+
6+
import org.springframework.beans.BeansException;
7+
import org.springframework.context.ApplicationContext;
8+
import org.springframework.context.ApplicationContextAware;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.ComponentScan;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.format.number.NumberStyleFormatter;
13+
import org.springframework.format.support.DefaultFormattingConversionService;
14+
import org.springframework.format.support.FormattingConversionService;
15+
import org.springframework.web.servlet.LocaleResolver;
16+
import org.springframework.web.servlet.ViewResolver;
17+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
18+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
19+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
20+
import org.springframework.web.servlet.i18n.FixedLocaleResolver;
21+
import org.thymeleaf.TemplateEngine;
22+
import org.thymeleaf.spring4.SpringTemplateEngine;
23+
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
24+
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
25+
import org.thymeleaf.templatemode.TemplateMode;
26+
import org.thymeleaf.templateresolver.ITemplateResolver;
27+
28+
import com.algaworks.brewer.controller.CervejasController;
29+
import com.algaworks.brewer.controller.converter.EstiloConverter;
30+
import com.algaworks.brewer.thymeleaf.BrewerDialect;
31+
32+
import nz.net.ultraq.thymeleaf.LayoutDialect;
33+
34+
@Configuration
35+
@ComponentScan(basePackageClasses = { CervejasController.class })
36+
@EnableWebMvc
37+
public class WebConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {
38+
39+
private ApplicationContext applicationContext;
40+
41+
@Override
42+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
43+
this.applicationContext = applicationContext;
44+
}
45+
46+
@Bean
47+
public ViewResolver viewResolver() {
48+
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
49+
resolver.setTemplateEngine(templateEngine());
50+
resolver.setCharacterEncoding("UTF-8");
51+
return resolver;
52+
}
53+
54+
@Bean
55+
public TemplateEngine templateEngine() {
56+
SpringTemplateEngine engine = new SpringTemplateEngine();
57+
engine.setEnableSpringELCompiler(true);
58+
engine.setTemplateResolver(templateResolver());
59+
60+
engine.addDialect(new LayoutDialect());
61+
engine.addDialect(new BrewerDialect());
62+
return engine;
63+
}
64+
65+
private ITemplateResolver templateResolver() {
66+
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
67+
resolver.setApplicationContext(applicationContext);
68+
resolver.setPrefix("classpath:/templates/");
69+
resolver.setSuffix(".html");
70+
resolver.setTemplateMode(TemplateMode.HTML);
71+
return resolver;
72+
}
73+
74+
@Override
75+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
76+
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
77+
}
78+
79+
@Bean
80+
public FormattingConversionService mvcConversionService() {
81+
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
82+
conversionService.addConverter(new EstiloConverter());
83+
84+
NumberStyleFormatter bigDecimalFormatter = new NumberStyleFormatter("#,##0.00");
85+
conversionService.addFormatterForFieldType(BigDecimal.class, bigDecimalFormatter);
86+
87+
NumberStyleFormatter integerFormatter = new NumberStyleFormatter("#,##0");
88+
conversionService.addFormatterForFieldType(Integer.class, integerFormatter);
89+
90+
return conversionService;
91+
}
92+
93+
@Bean
94+
public LocaleResolver localeResolver() {
95+
return new FixedLocaleResolver(new Locale("pt", "BR"));
96+
}
97+
98+
}

0 commit comments

Comments
 (0)