Skip to content

Commit 29b6233

Browse files
author
Ramesh Fadatare
committed
spring hibernate crud web app
1 parent ecf02cd commit 29b6233

28 files changed

+776
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="test" value="true"/>
17+
<attribute name="optional" value="true"/>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
25+
</attributes>
26+
</classpathentry>
27+
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.5 (2)">
28+
<attributes>
29+
<attribute name="owner.project.facets" value="jst.web"/>
30+
</attributes>
31+
</classpathentry>
32+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.8.0_201">
33+
<attributes>
34+
<attribute name="owner.project.facets" value="java"/>
35+
</attributes>
36+
</classpathentry>
37+
<classpathentry kind="output" path="target/classes"/>
38+
</classpath>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>springmvc-hibernate-crud-web-app</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.m2e.core.maven2Builder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.wst.validation.validationbuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
32+
<nature>org.eclipse.jdt.core.javanature</nature>
33+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
34+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
35+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
36+
</natures>
37+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="src/main/webapp"/>
4+
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
5+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
7+
<attributes>
8+
<attribute name="hide" value="true"/>
9+
</attributes>
10+
</classpathentry>
11+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
12+
<classpathentry kind="output" path=""/>
13+
</classpath>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.8
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
13+
org.eclipse.jdt.core.compiler.release=disabled
14+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2+
<wb-module deploy-name="springmvc-hibernate-crud-web-app">
3+
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
4+
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
6+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
7+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
8+
<property name="context-root" value="springmvc-hibernate-crud-web-app"/>
9+
<property name="java-output-path" value="/springmvc-hibernate-crud-web-app/target/classes"/>
10+
</wb-module>
11+
</project-modules>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<runtime name="Apache Tomcat v8.5 (2)"/>
4+
<fixed facet="wst.jsdt.web"/>
5+
<installed facet="java" version="1.5"/>
6+
<installed facet="jst.web" version="2.3"/>
7+
<installed facet="wst.jsdt.web" version="1.0"/>
8+
</faceted-project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
disabled=06target
2+
eclipse.preferences.version=1
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>net.javaguides.springmvc</groupId>
6+
<artifactId>springmvc-hibernate-crud-web-app</artifactId>
7+
<packaging>war</packaging>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<name>springmvc-hibernate-crud-web-app Maven Webapp</name>
10+
<url>http://maven.apache.org</url>
11+
<properties>
12+
<failOnMissingWebXml>false</failOnMissingWebXml>
13+
<spring.version>5.1.0.RELEASE</spring.version>
14+
<hibernate.version>5.3.5.Final</hibernate.version>
15+
<hibernate.validator>5.4.1.Final</hibernate.validator>
16+
<jstl.version>1.2.1</jstl.version>
17+
<tld.version>1.1.2</tld.version>
18+
<servlets.version>3.1.0</servlets.version>
19+
<jsp.version>2.3.1</jsp.version>
20+
</properties>
21+
<dependencies>
22+
<!-- Spring MVC Dependency -->
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-webmvc</artifactId>
26+
<version>${spring.version}</version>
27+
</dependency>
28+
<!-- Spring ORM -->
29+
<dependency>
30+
<groupId>org.springframework</groupId>
31+
<artifactId>spring-orm</artifactId>
32+
<version>${spring.version}</version>
33+
</dependency>
34+
<!-- Hibernate Core -->
35+
<dependency>
36+
<groupId>org.hibernate</groupId>
37+
<artifactId>hibernate-core</artifactId>
38+
<version>5.2.17.Final</version>
39+
</dependency>
40+
<!-- Hibernate Validator -->
41+
<dependency>
42+
<groupId>org.hibernate</groupId>
43+
<artifactId>hibernate-validator</artifactId>
44+
<version>${hibernate.validator}</version>
45+
</dependency>
46+
<!-- JSTL Dependency -->
47+
<dependency>
48+
<groupId>javax.servlet.jsp.jstl</groupId>
49+
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
50+
<version>${jstl.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>taglibs</groupId>
54+
<artifactId>standard</artifactId>
55+
<version>${tld.version}</version>
56+
</dependency>
57+
<!-- Servlet Dependency -->
58+
<dependency>
59+
<groupId>javax.servlet</groupId>
60+
<artifactId>javax.servlet-api</artifactId>
61+
<version>${servlets.version}</version>
62+
<scope>provided</scope>
63+
</dependency>
64+
<!-- JSP Dependency -->
65+
<dependency>
66+
<groupId>javax.servlet.jsp</groupId>
67+
<artifactId>javax.servlet.jsp-api</artifactId>
68+
<version>${jsp.version}</version>
69+
<scope>provided</scope>
70+
</dependency>
71+
<dependency>
72+
<groupId>mysql</groupId>
73+
<artifactId>mysql-connector-java</artifactId>
74+
<version>5.1.47</version>
75+
</dependency>
76+
</dependencies>
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<artifactId>maven-compiler-plugin</artifactId>
81+
<version>3.5.1</version>
82+
<configuration>
83+
<source>1.8</source>
84+
<target>1.8</target>
85+
</configuration>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.javaguides.springmvc.config;
2+
3+
import java.util.Properties;
4+
5+
import javax.sql.DataSource;
6+
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.PropertySource;
11+
import org.springframework.core.env.Environment;
12+
import org.springframework.jdbc.datasource.DriverManagerDataSource;
13+
import org.springframework.orm.hibernate5.HibernateTransactionManager;
14+
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
15+
import org.springframework.transaction.annotation.EnableTransactionManagement;
16+
17+
@Configuration
18+
@PropertySource("classpath:database.properties")
19+
@EnableTransactionManagement
20+
public class AppContext {
21+
22+
@Autowired
23+
private Environment environment;
24+
25+
@Bean
26+
public LocalSessionFactoryBean sessionFactory() {
27+
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
28+
sessionFactory.setDataSource(dataSource());
29+
sessionFactory.setPackagesToScan(new String[] {
30+
"net.javaguides.springmvc.entity"
31+
});
32+
sessionFactory.setHibernateProperties(hibernateProperties());
33+
return sessionFactory;
34+
}
35+
36+
@Bean
37+
public DataSource dataSource() {
38+
DriverManagerDataSource dataSource = new DriverManagerDataSource();
39+
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
40+
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
41+
dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
42+
dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));
43+
return dataSource;
44+
}
45+
46+
private Properties hibernateProperties() {
47+
Properties properties = new Properties();
48+
properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
49+
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
50+
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
51+
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
52+
return properties;
53+
}
54+
55+
@Bean
56+
public HibernateTransactionManager getTransactionManager() {
57+
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
58+
transactionManager.setSessionFactory(sessionFactory().getObject());
59+
return transactionManager;
60+
}
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.javaguides.springmvc.config;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
/**
6+
* @author Ramesh Fadatare
7+
*/
8+
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
9+
10+
@Override
11+
protected Class < ? > [] getRootConfigClasses() {
12+
return new Class[] {
13+
AppContext.class
14+
};
15+
//return null;
16+
}
17+
18+
@Override
19+
protected Class < ? > [] getServletConfigClasses() {
20+
return new Class[] {
21+
WebMvcConfig.class
22+
};
23+
}
24+
25+
@Override
26+
protected String[] getServletMappings() {
27+
return new String[] { "/" };
28+
}
29+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package net.javaguides.springmvc.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10+
import org.springframework.web.servlet.view.InternalResourceViewResolver;
11+
import org.springframework.web.servlet.view.JstlView;
12+
13+
/**
14+
* @author Ramesh Fadatare
15+
*/
16+
17+
@Configuration
18+
@EnableWebMvc
19+
@ComponentScan(basePackages = {
20+
"net.javaguides.springmvc"
21+
})
22+
public class WebMvcConfig implements WebMvcConfigurer {
23+
24+
@Bean
25+
public InternalResourceViewResolver resolver() {
26+
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
27+
resolver.setViewClass(JstlView.class);
28+
resolver.setPrefix("/WEB-INF/views/");
29+
resolver.setSuffix(".jsp");
30+
return resolver;
31+
}
32+
33+
@Override
34+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
35+
registry
36+
.addResourceHandler("/resources/**")
37+
.addResourceLocations("/resources/");
38+
}
39+
}

0 commit comments

Comments
 (0)