Hello World from OSS Silicon Valley


HowToUse/SpringFramework/4.0

_ Prerequisite

  • Java SDK installation
  • Maven installation (You can refer Overall/Maven)
  • Eclipse installation (You can refer Overall/Eclipse)
  • Tomcat installation
  • MySQL installation (You can refer Overall/MySQL)
  • MySQL Workbench

_ Install&Setup

Step.1
Create Maven project.
$ mkdir <project>
$ cd <project>
$ mvn archetype:generate -DgroupId=org.osssv -DartifactId=sample -DinteractiveMode=false -DarchetypeArtifactid=maven-archetype-quickstart
Step.2
Import existing maven project from Eclipse.

_ HowToUse

_ Prepare Spring framework

Step.1
Remove unnecessary source code such as App.java and AppTest.java.
Step.2
Edit POM.xml. (SAMPLE)
Step.3
Create Source Folder for "src/main/resources".
Step.4
Create src/main/webapp/WEB-INF.

_ Prepare Spring config files

Step.1
Create spring-context.xml in src/main/webapp/WEB-INF. (SAMPLE)
Step.2
Create web.xml in src/main/webapp/WEB-INF. (SAMPLE)
Step.3
Create log4j.properties in src/main/resources. (SAMPLE)
Step.4
Create properties directory in src/main/resources.
Step.5
Create database.properties in properties directory. (SAMPLE)

_ Create Database

Step.1
Launch MySQL Workbench
Step.2
Connect Database
Step.3
Create new model for DB schema and tables. (SAMPLE)
Step.4
Execute synchronization.

_ Create necessary packages

Step.1
Create entity and entity.impl package in main directories.
Step.2
Create repository and repository.impl package in main and test directories.
Step.3
Create service, service.impl and service.exception package in main and test directories.
Step.4
Create http, http.entity and http.exception package in main directories.
Step.5
Create util package in main directories.

_ Create interfaces

Step.1
Create User interface (SAMPLE) in entity package.
Step.2
Create UserRepository interface (SAMPLE) in repository package.
Step.3
Create UserService (SAMPLE) interface in service package.

_ Create exception classes for services

Step.1
Create ErrorCode enumerate (SAMPLE).
Step.2
Create Exception root classes (SAMPLE).
Step.3
Create Exception child classes (SAMPLE).

_ Create exception classes for http object

Step.1
Create HttpError class in http.exception package (SAMPLE).
Step.2
Create SampleExceptionMapper class in http.exception package (SAMPLE).

_ Create classes

Step.1
Create UserImpl class in entity.impl package (SAMPLE).
Step.2
Create UserRepositoryImpl class in repository.impl package (SAMPLE).
Step.3
Create UserServiceImpl class in service.impl package (SAMPLE).
Step.4
Create HttpUser class in http.entity package (SAMPLE).
Step.5
Create CustomContextLoaderListener class in util package for workaround (SAMPLE).

_ Create class for Presentation

Step.1
Create userResource class in http package (SAMPLE).

_ Create test classes

Step.1
Create TestUserRepository class in src/test/java (SAMPLE).

Don't forget inheritance.

extends AbstractTransactionalJUnit4SpringContextTests
Step.2
Create TestUserService class in src/test/java (SAMPLE).

Don't forget inheritance.

extends AbstractTransactionalJUnit4SpringContextTests

_ Launch Service

Step.1
Execute the following commands.
$ cd {PROJECT_HOME}
$ mvn test
Step.2
Execute the follwoing commands.
$ mvn tomcat7:run

You can access the application from http://localhost:8080/user.html.

_ Author

S.Yatsuzuka

Last-modified: 2015-08-17 (Mon) 02:41:34 (3168d)