Skip to content

Commit b8d379a

Browse files
SpringBootSecurityHibernateExample
1 parent 177e339 commit b8d379a

Some content is hidden

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

67 files changed

+16259
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mvn clean install
2+
mvn spring-boot:run
3+
url=> http://localhost:8080/
+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>SpringBootSecurityHibernateExample</groupId>
9+
<artifactId>SpringBootSecurityHibernateExample</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>1.3.1.RELEASE</version>
16+
</parent>
17+
18+
<organization>
19+
<name>ESpark</name>
20+
<url>http://adarshkumarsingh83.blogspot.in/</url>
21+
</organization>
22+
23+
<licenses>
24+
<license>
25+
<name>ESpark</name>
26+
<url>http://adarshkumarsingh83.blogspot.in/licenses/LICENSE-2.0.txt</url>
27+
<distribution>repo</distribution>
28+
</license>
29+
</licenses>
30+
31+
<developers>
32+
<developer>
33+
<id>adarshkumarsingh83</id>
34+
<name>Adarsh Kumar</name>
35+
<email>adarshkumarsingh83@gmail.com</email>
36+
<roles>
37+
<role>project architect</role>
38+
</roles>
39+
</developer>
40+
</developers>
41+
42+
<repositories>
43+
<repository>
44+
<id>maven2-repository.java.net</id>
45+
<name>Java.net Repository for Maven</name>
46+
<url>http://download.java.net/maven/2/</url>
47+
</repository>
48+
49+
<repository>
50+
<id>JBoss repository</id>
51+
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
52+
</repository>
53+
54+
<repository>
55+
<id>java.net</id>
56+
<url>https://maven.java.net/content/repositories/public/</url>
57+
</repository>
58+
59+
</repositories>
60+
61+
<properties>
62+
<project.name>SpringBootSecurityHibernateExample</project.name>
63+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
64+
<java.version>1.7</java.version>
65+
</properties>
66+
67+
<dependencies>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter</artifactId>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.springframework.boot</groupId>
76+
<artifactId>spring-boot-starter-freemarker</artifactId>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-starter-security</artifactId>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>org.springframework.boot</groupId>
86+
<artifactId>spring-boot-starter-data-jpa</artifactId>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>mysql</groupId>
91+
<artifactId>mysql-connector-java</artifactId>
92+
<version>5.1.31</version>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>org.apache.tomcat.embed</groupId>
97+
<artifactId>tomcat-embed-jasper</artifactId>
98+
<scope>provided</scope>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>javax.servlet</groupId>
103+
<artifactId>jstl</artifactId>
104+
</dependency>
105+
106+
<dependency>
107+
<groupId>org.springframework.boot</groupId>
108+
<artifactId>spring-boot-starter-test</artifactId>
109+
</dependency>
110+
</dependencies>
111+
112+
<build>
113+
<finalName>${project.name}</finalName>
114+
<outputDirectory>target/classes</outputDirectory>
115+
<plugins>
116+
<plugin>
117+
<artifactId>maven-compiler-plugin</artifactId>
118+
<configuration>
119+
<source>${java.version}</source>
120+
<target>${java.version}</target>
121+
<encoding>${project.build.sourceEncoding}</encoding>
122+
</configuration>
123+
</plugin>
124+
<plugin>
125+
<groupId>org.springframework.boot</groupId>
126+
<artifactId>spring-boot-maven-plugin</artifactId>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh;
32+
33+
import org.springframework.boot.SpringApplication;
34+
import org.springframework.boot.autoconfigure.SpringBootApplication;
35+
import org.springframework.boot.builder.SpringApplicationBuilder;
36+
import org.springframework.boot.context.web.SpringBootServletInitializer;
37+
/**
38+
* @author Adarsh Kumar
39+
* @author $LastChangedBy: Adarsh Kumar$
40+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
41+
* @Espark @copyright all right reserve
42+
*/
43+
@SpringBootApplication
44+
public class Application extends SpringBootServletInitializer {
45+
46+
public static void main(String[] args) {
47+
SpringApplication.run(Application.class, args);
48+
}
49+
50+
@Override
51+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
52+
return application.sources(Application.class);
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.bean;
32+
33+
import java.io.Serializable;
34+
35+
/**
36+
* @author Adarsh Kumar
37+
* @author $LastChangedBy: Adarsh Kumar$
38+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
39+
* @Espark @copyright all right reserve
40+
*/
41+
public class ResponseBean<T> implements Serializable{
42+
43+
private T data;
44+
private String message;
45+
46+
public T getData() {
47+
return data;
48+
}
49+
50+
public void setData(T data) {
51+
this.data = data;
52+
}
53+
54+
public String getMessage() {
55+
return message;
56+
}
57+
58+
public void setMessage(String message) {
59+
this.message = message;
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.configuration.persistence;
32+
33+
import org.springframework.beans.factory.annotation.Value;
34+
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.context.annotation.PropertySource;
37+
import org.springframework.jdbc.datasource.DriverManagerDataSource;
38+
import org.springframework.orm.hibernate4.HibernateTransactionManager;
39+
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
40+
import org.springframework.transaction.annotation.EnableTransactionManagement;
41+
42+
import javax.sql.DataSource;
43+
import java.util.Properties;
44+
/**
45+
* @author Adarsh Kumar
46+
* @author $LastChangedBy: Adarsh Kumar$
47+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
48+
* @Espark @copyright all right reserve
49+
*/
50+
@Configuration
51+
@EnableTransactionManagement
52+
@PropertySource("classpath:/application.properties")
53+
public class PersistenceConfigurations {
54+
55+
@Value("${db.driver}")
56+
private String DB_DRIVER;
57+
58+
@Value("${db.password}")
59+
private String DB_PASSWORD;
60+
61+
@Value("${db.url}")
62+
private String DB_URL;
63+
64+
@Value("${db.username}")
65+
private String DB_USERNAME;
66+
67+
@Value("${hibernate.dialect}")
68+
private String HIBERNATE_DIALECT;
69+
70+
@Value("${hibernate.show_sql}")
71+
private String HIBERNATE_SHOW_SQL;
72+
73+
@Value("${hibernate.hbm2ddl.auto}")
74+
private String HIBERNATE_HBM2DDL_AUTO;
75+
76+
@Bean
77+
public DataSource dataSource() {
78+
DriverManagerDataSource dataSource = new DriverManagerDataSource();
79+
dataSource.setDriverClassName(DB_DRIVER);
80+
dataSource.setUrl(DB_URL);
81+
dataSource.setUsername(DB_USERNAME);
82+
dataSource.setPassword(DB_PASSWORD);
83+
return dataSource;
84+
}
85+
86+
@Bean
87+
public LocalSessionFactoryBean sessionFactory() {
88+
LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
89+
sessionFactoryBean.setDataSource(dataSource());
90+
sessionFactoryBean.setPackagesToScan("com.espark.adarsh");
91+
Properties hibernateProperties = new Properties();
92+
hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
93+
hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
94+
hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
95+
sessionFactoryBean.setHibernateProperties(hibernateProperties);
96+
97+
return sessionFactoryBean;
98+
}
99+
100+
@Bean
101+
public HibernateTransactionManager transactionManager() {
102+
HibernateTransactionManager transactionManager =
103+
new HibernateTransactionManager();
104+
transactionManager.setSessionFactory(sessionFactory().getObject());
105+
return transactionManager;
106+
}
107+
108+
}

0 commit comments

Comments
 (0)