Skip to content

Commit

Permalink
* Начата переработка под Spring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ksenomorfa committed Jun 17, 2016
1 parent 5c492b4 commit 09b0df0
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 23 deletions.
40 changes: 39 additions & 1 deletion BugTracker.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</webroots>
<sourceRoots>
<root url="file://$MODULE_DIR$/src/main/java" />
<root url="file://$MODULE_DIR$/src/main/webapp/resources" />
<root url="file://$MODULE_DIR$/src/main/webapp/static/resources" />
</sourceRoots>
</configuration>
</facet>
Expand All @@ -33,6 +33,20 @@
<deploymentDescriptor name="hibernate.cfg.xml" url="file://$MODULE_DIR$/src/main/webapp/resources/hibernate.cfg.xml" />
</configuration>
</facet>
<facet type="Spring" name="Spring">
<configuration>
<fileset id="web application context" name="MVC application context" removed="true">
<file>file://$MODULE_DIR$/src/main/webapp/WEB-INF/dispatcher-servlet.xml</file>
<file>file://$MODULE_DIR$/src/main/webapp/WEB-INF/spring-security.xml</file>
</fileset>
<fileset id="web dispatcher servlet context" name="MVC dispatcher servlet context" removed="true">
<file>file://$MODULE_DIR$/src/main/webapp/WEB-INF/dispatcher-servlet.xml</file>
</fileset>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/webapp/WEB-INF/dispatcher-servlet.xml</file>
</fileset>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
Expand All @@ -46,6 +60,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="postgresql-9.4.1208.jre6" level="project" />
<orderEntry type="library" name="Java EE 6-Java EE 6" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.6.2" level="project" />
Expand All @@ -54,6 +69,7 @@
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
Expand All @@ -68,5 +84,27 @@
<orderEntry type="library" name="Maven: com.mchange:c3p0:0.9.5" level="project" />
<orderEntry type="library" name="Maven: com.mchange:mchange-commons-java:0.2.9" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-c3p0:5.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:4.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:4.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:4.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-taglibs:4.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-acl:4.1.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-orm:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.2.5.RELEASE" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:jstl:1.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.3.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.5.0.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:jcl-over-slf4j:1.7.1" level="project" />
</component>
</module>
83 changes: 78 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>BugTracker</name>
<!--<properties>
</properties>-->

<properties>
<spring.version>4.2.5.RELEASE</spring.version>
<spring.security.version>RELEASE</spring.security.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -39,6 +40,11 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
Expand All @@ -59,7 +65,6 @@
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
Expand All @@ -85,6 +90,74 @@
<artifactId>hibernate-c3p0</artifactId>
<version>5.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.security.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>BugTracker</finalName>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/ru/polinabevad/bugtracker/dao/MessageDao.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package ru.polinabevad.bugtracker.dao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.polinabevad.bugtracker.core.Message;
import ru.polinabevad.bugtracker.core.Task;

import java.util.ArrayList;
import java.util.Collection;

// DAO - Data Access Object
@Service("MessageDao")
@Transactional
public class MessageDao<T> extends DAO<Message, Integer> {
public Message findById(Integer id) {
return (Message) getCurrentSession().get(Message.class, id);
Expand All @@ -18,7 +23,7 @@ public ArrayList<Message> findAll() {

public ArrayList<Message> findByTaskId(Integer taskId) {
return (ArrayList<Message>) getCurrentSession().createQuery("FROM Message " +
" WHERE taskId=" + taskId)
" WHERE task=" + taskId)
.list();
}

Expand All @@ -34,7 +39,7 @@ public void deleteFromTo(Integer from, Integer to) {
.executeUpdate();
}

public void deleteById(Integer id) {
private void deleteById(Integer id) {
getCurrentSession().createQuery("DELETE FROM Message " +
"WHERE id = :id")
.setParameter("id", id)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/ru/polinabevad/bugtracker/dao/PeopleDao.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ru.polinabevad.bugtracker.dao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.polinabevad.bugtracker.core.People;

import java.util.ArrayList;
import java.util.Collection;

// DAO - Data Access Object
@Service("PeopleDao")
@Transactional
public class PeopleDao<T> extends DAO<People, Integer> {
public People findById(Integer id) {
return (People) getCurrentSession().get(People.class, id);
Expand All @@ -28,7 +32,7 @@ public void deleteFromTo(Integer from, Integer to) {
.executeUpdate();
}

public void deleteById(Integer id) {
private void deleteById(Integer id) {
getCurrentSession().createQuery("DELETE FROM People " +
"WHERE id = :id")
.setParameter("id", id)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/ru/polinabevad/bugtracker/dao/TaskDao.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ru.polinabevad.bugtracker.dao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.polinabevad.bugtracker.core.Task;

import java.util.ArrayList;
import java.util.Collection;

// DAO - Data Access Object
@Service("TaskDao")
@Transactional
public class TaskDao<T> extends DAO<Task, Integer> {

public Task findById(Integer id) {
Expand All @@ -29,7 +33,7 @@ public void deleteFromTo(Integer from, Integer to) {
.executeUpdate();
}

public void deleteById(Integer id) {
private void deleteById(Integer id) {
getCurrentSession().createQuery("DELETE FROM Task " +
"WHERE id = :id")
.setParameter("id", id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.polinabevad.bugtracker.services;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class MainController {
@RequestMapping("/")
public String helloWorld(Model model) {
model.addAttribute("message", "Hello World!");
return "index";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ private static SessionFactory buildSessionFactory() {

System.out.println("hibernate.connection.username = " + configuration.getProperties().getProperty("hibernate.connection.username"));
System.out.println("hibernate.connection.password = " + configuration.getProperties().getProperty("hibernate.connection.password"));
System.out.println("hibernate.c3p0.min_size = " + configuration.getProperties().getProperty("hibernate.c3p0.min_size"));
System.out.println("hibernate.c3p0.max_size = " + configuration.getProperties().getProperty("hibernate.c3p0.max_size"));
System.out.println("hibernate.hbm2ddl.auto = " + configuration.getProperties().getProperty("hibernate.hbm2ddl.auto"));
System.out.println("hibernate.c3p0.timeout = " + configuration.getProperties().getProperty("hibernate.c3p0.timeout"));
System.out.println("hibernate.c3p0.max_statements = " + configuration.getProperties().getProperty("hibernate.c3p0.max_statements"));

return configuration.buildSessionFactory(
new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
Expand Down
25 changes: 25 additions & 0 deletions src/main/webapp/WEB-INF/dispatcher-servlet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
">

<context:annotation-config/>

<context:component-scan base-package="ru.polinabevad.bugtracker"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<head>
<title>Стартовая страница Баг-трекера</title>
<!-- Пока css стили тут, нужно вынести отдельно-->
<link rel="stylesheet" href="./resources/clearcss.css">
<link rel="stylesheet" href="./resources/index.css">
<link rel="stylesheet" href="resources/clearcss.css">
<link rel="stylesheet" href="resources/index.css">

</head>
<body>
Expand Down
46 changes: 37 additions & 9 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0"
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_3_0.xsd">

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcher-servlet.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<display-name>BugTracker with Maven, TomCat, Junit</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

<session-config>
<session-timeout>30</session-timeout>
</session-config>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>

</web-app>
2 changes: 2 additions & 0 deletions src/main/webapp/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<session-factory>
<property name="connection.url">jdbc:postgresql://localhost:5432/BugTrackerBase</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">AhuleB2KS</property>
<!-- DB schema will be updated if needed -->
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
Expand Down
Loading

0 comments on commit 09b0df0

Please sign in to comment.