Skip to content

Commit b3ae916

Browse files
committed
Projeto do curso
1 parent 9332531 commit b3ae916

File tree

821 files changed

+464404
-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.

821 files changed

+464404
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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+
</properties>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<version>${maven-compiler-pluging.version}</version>
54+
<configuration>
55+
<source>${java.version}</source>
56+
<target>${java.version}</target>
57+
</configuration>
58+
</plugin>
59+
60+
<plugin>
61+
<groupId>org.flywaydb</groupId>
62+
<artifactId>flyway-maven-plugin</artifactId>
63+
<version>${flyway-maven-plugin.version}</version>
64+
<configuration>
65+
<driver>com.mysql.jdbc.Driver</driver>
66+
</configuration>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
<dependencyManagement>
72+
<dependencies>
73+
<dependency>
74+
<groupId>org.springframework</groupId>
75+
<artifactId>spring-framework-bom</artifactId>
76+
<version>${spring-framework.version}</version>
77+
<type>pom</type>
78+
<scope>import</scope>
79+
</dependency>
80+
</dependencies>
81+
</dependencyManagement>
82+
83+
<dependencies>
84+
<!-- Spring MVC -->
85+
<dependency>
86+
<groupId>org.springframework</groupId>
87+
<artifactId>spring-webmvc</artifactId>
88+
<scope>compile</scope>
89+
<exclusions>
90+
<exclusion>
91+
<groupId>commons-logging</groupId>
92+
<artifactId>commons-logging</artifactId>
93+
</exclusion>
94+
</exclusions>
95+
</dependency>
96+
97+
<!-- Servlet API -->
98+
<dependency>
99+
<groupId>javax.servlet</groupId>
100+
<artifactId>javax.servlet-api</artifactId>
101+
<version>${servlet.version}</version>
102+
<scope>provided</scope>
103+
</dependency>
104+
105+
<!-- Thymeleaf -->
106+
<dependency>
107+
<groupId>org.thymeleaf</groupId>
108+
<artifactId>thymeleaf</artifactId>
109+
<version>${thymeleaf.version}</version>
110+
<scope>compile</scope>
111+
</dependency>
112+
113+
<dependency>
114+
<groupId>org.thymeleaf</groupId>
115+
<artifactId>thymeleaf-spring4</artifactId>
116+
<version>${thymeleaf.version}</version>
117+
<scope>compile</scope>
118+
</dependency>
119+
120+
<!-- Bean Validation / Hibernate Validator -->
121+
<dependency>
122+
<groupId>org.hibernate</groupId>
123+
<artifactId>hibernate-validator</artifactId>
124+
<version>${hibernate-validator.version}</version>
125+
<scope>compile</scope>
126+
</dependency>
127+
128+
<!-- Thymeleaf - Layout Dialect -->
129+
<dependency>
130+
<groupId>nz.net.ultraq.thymeleaf</groupId>
131+
<artifactId>thymeleaf-layout-dialect</artifactId>
132+
<version>${thymeleaf-layout-dialect.version}</version>
133+
</dependency>
134+
135+
<!-- Logging -->
136+
<dependency>
137+
<groupId>org.apache.logging.log4j</groupId>
138+
<artifactId>log4j-slf4j-impl</artifactId>
139+
<version>${log4j.version}</version>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.apache.logging.log4j</groupId>
143+
<artifactId>log4j-api</artifactId>
144+
<version>${log4j.version}</version>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.apache.logging.log4j</groupId>
148+
<artifactId>log4j-core</artifactId>
149+
<version>${log4j.version}</version>
150+
</dependency>
151+
<dependency>
152+
<groupId>org.slf4j</groupId>
153+
<artifactId>jcl-over-slf4j</artifactId>
154+
<version>${jcl-over-slf4j.version}</version>
155+
</dependency>
156+
157+
<!-- JPA / Hibernate -->
158+
<dependency>
159+
<groupId>org.hibernate</groupId>
160+
<artifactId>hibernate-entitymanager</artifactId>
161+
<version>${hibernate.version}</version>
162+
<scope>compile</scope>
163+
</dependency>
164+
165+
<!-- Hibernate - Java 8 support -->
166+
<dependency>
167+
<groupId>org.hibernate</groupId>
168+
<artifactId>hibernate-java8</artifactId>
169+
<version>${hibernate.version}</version>
170+
<scope>compile</scope>
171+
</dependency>
172+
173+
<!-- MySQL Driver -->
174+
<dependency>
175+
<groupId>mysql</groupId>
176+
<artifactId>mysql-connector-java</artifactId>
177+
<version>${mysql-connector-java.version}</version>
178+
<scope>provided</scope>
179+
</dependency>
180+
181+
<!-- Spring Data JPA -->
182+
<dependency>
183+
<groupId>org.springframework.data</groupId>
184+
<artifactId>spring-data-jpa</artifactId>
185+
<version>${spring-data-jpa.version}</version>
186+
</dependency>
187+
188+
</dependencies>
189+
190+
<repositories>
191+
<repository>
192+
<id>sonatype-nexus-snapshots</id>
193+
<name>Sonatype Nexus Snapshots</name>
194+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
195+
<snapshots>
196+
<enabled>true</enabled>
197+
</snapshots>
198+
</repository>
199+
</repositories>
200+
201+
</project>
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.algaworks.brewer.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
import com.algaworks.brewer.service.CadastroCervejaService;
7+
8+
@Configuration
9+
@ComponentScan(basePackageClasses = CadastroCervejaService.class)
10+
public class ServiceConfig {
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.algaworks.brewer.config;
2+
3+
import org.springframework.beans.BeansException;
4+
import org.springframework.context.ApplicationContext;
5+
import org.springframework.context.ApplicationContextAware;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.format.support.DefaultFormattingConversionService;
10+
import org.springframework.format.support.FormattingConversionService;
11+
import org.springframework.web.servlet.ViewResolver;
12+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
13+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
14+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
15+
import org.thymeleaf.TemplateEngine;
16+
import org.thymeleaf.spring4.SpringTemplateEngine;
17+
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
18+
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
19+
import org.thymeleaf.templatemode.TemplateMode;
20+
import org.thymeleaf.templateresolver.ITemplateResolver;
21+
22+
import com.algaworks.brewer.controller.CervejasController;
23+
import com.algaworks.brewer.controller.converter.EstiloConverter;
24+
25+
import nz.net.ultraq.thymeleaf.LayoutDialect;
26+
27+
@Configuration
28+
@ComponentScan(basePackageClasses = { CervejasController.class })
29+
@EnableWebMvc
30+
public class WebConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {
31+
32+
private ApplicationContext applicationContext;
33+
34+
@Override
35+
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
36+
this.applicationContext = applicationContext;
37+
}
38+
39+
@Bean
40+
public ViewResolver viewResolver() {
41+
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
42+
resolver.setTemplateEngine(templateEngine());
43+
resolver.setCharacterEncoding("UTF-8");
44+
return resolver;
45+
}
46+
47+
@Bean
48+
public TemplateEngine templateEngine() {
49+
SpringTemplateEngine engine = new SpringTemplateEngine();
50+
engine.setEnableSpringELCompiler(true);
51+
engine.setTemplateResolver(templateResolver());
52+
53+
engine.addDialect(new LayoutDialect());
54+
return engine;
55+
}
56+
57+
private ITemplateResolver templateResolver() {
58+
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
59+
resolver.setApplicationContext(applicationContext);
60+
resolver.setPrefix("classpath:/templates/");
61+
resolver.setSuffix(".html");
62+
resolver.setTemplateMode(TemplateMode.HTML);
63+
return resolver;
64+
}
65+
66+
@Override
67+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
68+
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
69+
}
70+
71+
@Bean
72+
public FormattingConversionService mvcConversionService() {
73+
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
74+
conversionService.addConverter(new EstiloConverter());
75+
76+
return conversionService;
77+
}
78+
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.algaworks.brewer.config.init;
2+
3+
import javax.servlet.Filter;
4+
5+
import org.springframework.web.filter.CharacterEncodingFilter;
6+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
7+
8+
import com.algaworks.brewer.config.JPAConfig;
9+
import com.algaworks.brewer.config.ServiceConfig;
10+
import com.algaworks.brewer.config.WebConfig;
11+
12+
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
13+
14+
@Override
15+
protected Class<?>[] getRootConfigClasses() {
16+
return new Class<?>[] { JPAConfig.class, ServiceConfig.class };
17+
}
18+
19+
@Override
20+
protected Class<?>[] getServletConfigClasses() {
21+
return new Class<?>[] { WebConfig.class };
22+
}
23+
24+
@Override
25+
protected String[] getServletMappings() {
26+
return new String[] { "/" };
27+
}
28+
29+
@Override
30+
protected Filter[] getServletFilters() {
31+
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
32+
characterEncodingFilter.setEncoding("UTF-8");
33+
characterEncodingFilter.setForceEncoding(true);
34+
35+
return new Filter[] { characterEncodingFilter };
36+
}
37+
38+
}

0 commit comments

Comments
 (0)