Skip to content

Commit bacfbea

Browse files
committed
init
0 parents  commit bacfbea

File tree

8 files changed

+240
-0
lines changed

8 files changed

+240
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.classpath
2+
.project
3+
.settings/
4+
docker-compose.yml
5+
target/
6+

pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>pl.coderslab</groupId>
4+
<artifactId>app</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<properties>
9+
<org.springframework-version>4.3.7.RELEASE</org.springframework-version>
10+
<failOnMissingWebXml>false</failOnMissingWebXml>
11+
<maven.compiler.source>1.8</maven.compiler.source>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
</properties>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework</groupId>
18+
<artifactId>spring-webmvc</artifactId>
19+
<version>${org.springframework-version}</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>javax.servlet</groupId>
24+
<artifactId>javax.servlet-api</artifactId>
25+
<version>3.1.0</version>
26+
<scope>provided</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>javax.servlet</groupId>
31+
<artifactId>jstl</artifactId>
32+
<version>1.2</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.hibernate</groupId>
37+
<artifactId>hibernate-core</artifactId>
38+
<version>5.2.9.Final</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-orm</artifactId>
43+
<version>4.3.7.RELEASE</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>mysql</groupId>
47+
<artifactId>mysql-connector-java</artifactId>
48+
<version>5.1.39</version>
49+
</dependency>
50+
51+
52+
</dependencies>
53+
54+
</project>
55+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package pl.coderslab;
2+
3+
import javax.persistence.EntityManagerFactory;
4+
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.orm.jpa.JpaTransactionManager;
9+
import org.springframework.orm.jpa.LocalEntityManagerFactoryBean;
10+
import org.springframework.transaction.annotation.EnableTransactionManagement;
11+
import org.springframework.web.servlet.ViewResolver;
12+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
13+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
14+
import org.springframework.web.servlet.view.InternalResourceViewResolver;
15+
16+
@Configuration
17+
@EnableWebMvc
18+
@ComponentScan(basePackages = "pl.coderslab")
19+
@EnableTransactionManagement
20+
public class AppConfig extends WebMvcConfigurerAdapter{
21+
22+
@Bean
23+
public ViewResolver viewResolver() {
24+
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
25+
viewResolver.setPrefix("/WEB-INF/views/");
26+
viewResolver.setSuffix(".jsp");
27+
return viewResolver;
28+
}
29+
30+
@Bean
31+
public LocalEntityManagerFactoryBean entityManagerFactory() {
32+
LocalEntityManagerFactoryBean emfb = new LocalEntityManagerFactoryBean();
33+
emfb.setPersistenceUnitName("defaultConnection");
34+
return emfb;
35+
}
36+
37+
@Bean
38+
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
39+
JpaTransactionManager tm = new JpaTransactionManager(emf);
40+
return tm;
41+
}
42+
43+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package pl.coderslab;
2+
3+
import javax.servlet.ServletContext;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.ServletRegistration;
6+
7+
import org.springframework.web.WebApplicationInitializer;
8+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
9+
import org.springframework.web.servlet.DispatcherServlet;
10+
11+
public class AppInitializer implements WebApplicationInitializer {
12+
13+
@Override
14+
public void onStartup(ServletContext container) throws ServletException {
15+
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
16+
ctx.register(AppConfig.class);
17+
ctx.setServletContext(container);
18+
19+
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
20+
servlet.setLoadOnStartup(1);
21+
servlet.addMapping("/");
22+
}
23+
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package pl.coderslab.app;
2+
3+
public class SpringDiApplication {
4+
5+
public static void main(String[] args) {
6+
7+
8+
}
9+
10+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package pl.coderslab.entity;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
@Entity(name="books")
9+
public class Book {
10+
11+
@Id
12+
@GeneratedValue(strategy=GenerationType.IDENTITY)
13+
private Long id;
14+
private String title;
15+
private String author;
16+
private double rating;
17+
private String publisher;
18+
private String description;
19+
20+
public Long getId() {
21+
return id;
22+
}
23+
public void setId(Long id) {
24+
this.id = id;
25+
}
26+
public String getTitle() {
27+
return title;
28+
}
29+
public void setTitle(String title) {
30+
this.title = title;
31+
}
32+
public String getAuthor() {
33+
return author;
34+
}
35+
public void setAuthor(String author) {
36+
this.author = author;
37+
}
38+
public double getRating() {
39+
return rating;
40+
}
41+
public void setRating(double rating) {
42+
this.rating = rating;
43+
}
44+
public String getPublisher() {
45+
return publisher;
46+
}
47+
public void setPublisher(String publisher) {
48+
this.publisher = publisher;
49+
}
50+
public String getDescription() {
51+
return description;
52+
}
53+
public void setDescription(String description) {
54+
this.description = description;
55+
}
56+
57+
58+
59+
60+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
5+
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
6+
version="2.1">
7+
<persistence-unit name="defaultConnection">
8+
<properties>
9+
<property name="javax.persistence.jdbc.url"
10+
value="jdbc:mysql://localhost:3306/test" />
11+
<property name="javax.persistence.jdbc.user" value="root" />
12+
<property name="javax.persistence.jdbc.password" value="password" />
13+
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
14+
<property name="javax.persistence.schema-generation.database.action"
15+
value="create"/>
16+
17+
<property name="hibernate.hbm2ddl.auto" value="update"/>
18+
<property name="hibernate.show_sql" value="true"/>
19+
<property name="hibernate.format_sql" value="true"/>
20+
21+
<property name="hibernate.dialect"
22+
value="org.hibernate.dialect.MySQL5InnoDBDialect" />
23+
<property name="hibernate.connection.useUnicode" value="true" />
24+
<property name="hibernate.connection.characterEncoding" value="utf8" />
25+
<property name="hibernate.connection.CharSet" value="utf8" />
26+
27+
28+
</properties>
29+
</persistence-unit>
30+
</persistence>

src/main/webapp/WEB-INF/web.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
3+
<display-name>app</display-name>
4+
<welcome-file-list>
5+
<welcome-file>index.html</welcome-file>
6+
<welcome-file>index.htm</welcome-file>
7+
<welcome-file>index.jsp</welcome-file>
8+
<welcome-file>default.html</welcome-file>
9+
<welcome-file>default.htm</welcome-file>
10+
<welcome-file>default.jsp</welcome-file>
11+
</welcome-file-list>
12+
</web-app>

0 commit comments

Comments
 (0)