This is the homepage of Java/Spring course organized on Wrocław Uniwersity of Technology by PGS Software in Spring 2017.
Our goal is to go through key aspects of professional development of web application based on the most popular Java web framework - Spring.
After the course, we would like to invite some of you to participate in summer internship program at PGS Software. Do not worry, its paid internship, and you will be able to put your newly acquired knowledge in practice in real-world challenges in renowned software house. Perhaps later you would like to stay with us longer…
- Classes on March 28th will be in room 007, same as march 21st.
- Please fill in an anonymous questionaire: https://www.biurokarier.pwr.edu.pl/aktualnosci/110/badanie-moj-idealny-pracodawca
FILL the questionare for chapter 6 in agenda
- Provide 60% of coverage for source code from previous chapter
- Write Hamcrest matchers
isPresent
andisEmpty
. First matches when Optional.isPresent() is true, the other when Optional.empty() is true - Write Matcher named
exchangesFrom
that takes a currency as an arugment and matches when CurrencyPair contains 'from currency'`corresponding to matcher's argument - Write a method in
business-logic-implementation
that returns all currency pairs from database. Mock repository so it returns 5 different currency pairs and useexchangeFrom
matcher along withhasItem
matcher sohasItem(exchangeFrom(PLN))
matches if returned collection contains at least one pair with PLN as base currency
Resources:
- Java doc for
hasItem
matcher: http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/CoreMatchers.html#hasItems(org.hamcrest.Matcher...) - Introduction to unit testing: https://howtotrainyourjava.com/2017/03/23/unit-testing-basics/
Fill the questionaire for chapter 5 in agenda
- Modify existing endpoints, that result in a query to fixer.io, to save exchange rates in database. The entry should contain rates of few common currencies to EUR and date.
- Add a new GET endpoint that will return last entry from database.
- Add a new PUT endpoint that will save new entry provided in request body in database and return current number of entries.
- Add a new DELETE endpoint that will remove one entry based on provided id.
- Add a new POST endpoint expecting body containing currency code and two dates and returning statistics from this period including: (but not limited to) average, minimum and maximum rates to EUR and number of entries.
- Redesign the database - use two tables instead of one. First should contain id, currency code and name. Second should have id, date, use two foreign keys from first table and store exchange rates between two arbitrary currencies in one entry. Add new endpoints to handle new design. Experiment :)
Resources:
- Spring DATA JPA documentation: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/
- Guide how to start: https://howtotrainyourjava.com/2017/03/16/spring-data-jpa-basics/
Fill the questionaire for chapter 4 in agenda
Add to an existing application endpoints that will:
- Accept GET request with source currency and target currency and return exchange rates based on real data from http://fixer.io/
- Accept GET request with source currency and multiple target currencies and return rates for each one
- Do the same, but accept POST request with a JSON body containing those parameters
- Accept a number between 0 and 1000, source currency and target currency and performs conversion
- Add date as parameter to present historical results
- Return some status codes besides "200 OK" and "500 Internal Server Error"
Resources:
- How to build own webervice: https://howtotrainyourjava.com/2017/03/09/spring-web-basics/
- How to use external webservice: https://spring.io/guides/gs/consuming-rest/
Please also fill in the questionaire attached to description of chapter 3. Fron now on the questionaire will be attached to each chapter
Split existing application into several maven modules with following naming and content:
- rest client - contains the
DemoApplication
along with controllers - business logic interface - contains technology agnostic interfaces
- business logic implementation - contains classes implementing interfaces
- rest client - leave empty for now
- database - leave empty for now
You may have use of following resources
- guide to modules: http://books.sonatype.com/mvnex-book/reference/multimodule.html
- guide to configuration: http://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/reference/html/ch03.html
- some basics of Spring core: https://howtotrainyourjava.com/2017/02/23/spring-core-basics/
-
Prepare a release using maven release plugin (http://maven.apache.org/maven-release/maven-release-plugin/) As a result the artefact should be deployed to local instance of nexus (download version 2 from https://www.sonatype.com/download-oss-sonatype) and tagged properly on your github repository
-
Try the difference between @RestController and @Controller, add new method that will return CurrencyDTO that includes Currency and BigDecimal objects.
- The course will start March 7 (Tuesday)
- The course will consist of eight meetings, carried over six weeks:
- 07.03.2017
- 09.03.2017
- 14.03.2017
- 16.03.2017
- 21.03.2017
- 28.03.2017
- 04.04.2017
- 11.04.2017
- Classes will start at 5pm and last two hours.
- Classes will take place at Wrocław University of Technology, plac Grunwaldzki 11, 50-377 Wrocław, building D-21, room 201
- You can contact us via [email protected]
- At the last class, there will be written exam, mandatory to pass the course.
- Basic Java SE skills is the only hard requirement. We would like to focus on how to implement features in given framework, environment, tools, clean code, good practices etc. not the basics of language itself.
- The lecture / workshop will be in Polish
- Written materials will be mostly in English
Note, that this may be subject to change depending on how fast we will be able to go.
- Intro, rules and organizational stuff.
- An overview of the application we will build during the course.
- IDE: Eclipse / Intellij IDEA.
- Version control: GIT, GitHub.
- Build tool: Maven.
- Deployment: Tomcat, Heroku.
- Code enhancement: Project Lombok
- Basics of HTTP, request, response, servlets
- Basics of Java web applications.
- Application configuration.
- Spring Boot.
- Beans, scopes, annotations, factories, contexts.
https://docs.google.com/forms/d/1Enr7B2JxDPIqGDwOajTreTCIimgbtshanfD457UbMKM
- HTTP methods, Servlets, JSON
- Web services, REST
- Processing incoming requests
- Outgoing requests - RestTemplate
- Tools – Postman.
https://docs.google.com/forms/d/1OkYfO5MBPqwf3KQmKElG3koCXyxRdYuywJ1FrioBAPw
- SQL and relational databases.
- JPA, Object-Relational Mapping.
- Spring Data.
https://docs.google.com/forms/d/1_ZXTBJIELdcloLxn3zo4OLvjTH98Ty3uFh5XFRf9Tqw
https://docs.google.com/forms/d/1YPj5RAbxR7obPBu1v9hlwYExZg6f_XaTjFVn6kefuqs
- Spring Security
- JHipster frontend
- Logging frameworks
https://docs.google.com/forms/d/1zzWLu5B29GmQenMjjLigIaXYRUwbMaYaH6VI9qdFQkU
- HTTP Error codes and Java exceptions
- Advanced Spring features and more
- Written exam
Aside from links in the agenda:
- Spring - guides
- Spring framework Reference Documentation
- Spring Boot Reference Guide
- How To Train Your Java articles on / near Spring
- Varanasi Balaji, Belida Sudha: Spring REST
- Sam Newman: Building Microservices
- Craig Walls: Spring in action
Pluralsight has some good courses. It is paid service, but there is a 30 days free trial:
- Spring Fundamentals
- REST Fundamentals
- Architecting Web Applications with Spring
- Getting Started with Spring Data JPA
- Maven Fundamentals
- Unit Testing In Java With JUnit
Environment preparation from ground up.
- Create an account on GitHub if you don’t yet have one: https://github.com/
- Download SourceTree (recommended) from https://www.sourcetreeapp.com/ or command line client from https://git-scm.com/downloads
- Install
- Clone / new -> source path: https://github.com/Gvaireth/java-spring-course-pwr-2017.git Or “git clone https://github.com/Gvaireth/java-spring-course-pwr-2017.git [source folder name]”
- More info on git: https://git-scm.com/doc
- Download MySQL Installer from https://dev.mysql.com/downloads/installer/
- Run
- [License Agreement]: Accept, Next
- [Setup Type]: choose “Developer Default”, Next
- [Installation]: Execute, Next
- [Type and Networking]: use default settings, Next
- [Account and Roles]: choose root password, Next
- [Windows Service]: choose default settings, Next
- [Connect To Server]: Check, Next
- Apply Server Configuration: Execute, Finish
- Download MySQL Workbench from: https://dev.mysql.com/downloads/workbench/
- Run
- Press “Download Prerequisites” if needed, it will open download page for: Microsoft .NET Framework 4.5 (offline installer at: https://www.microsoft.com/en-us/download/details.aspx?id=42642) Visual C++ Redistributable for Visual Studio 2015
- Install one or both, restart MySQL Workbench Installer
- Next, Next
- [Setup Type]: choose “Complete”, Next,
- Install, Finish
- [Welcome to MySQL Workbench]: Local Instance MySQL57, Connect
- Download Java SE Development Kit 8u121 from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Accept License Agreements
- Run, Next, Next
- Set JAVA_HOME, example for Windows: https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html
- Download Eclipse IDE for Java EE Developers from https://www.eclipse.org/downloads/eclipse-packages/
- Choose 64 bit version if you installed 64 bit version of JDK
- Install
- Download lombok.jar from https://projectlombok.org/download.html
- Run jar (using “Java (TE) Platform SE Binary” on Windows)
- If it says it can’t find any IDE on your computer, specify eclipse.exe location -> Install / Update
- It should add -javaagent:lombok.jar to -vmargs in eclipse.ini and lombok.jar file in Eclipse root folder
- Restart Eclipse if it’s running
- File -> Import -> Maven-> Existing Maven Projects -> Next
- Select WeatherForecast as root directory. You should have root pom.xml file displayed and submodules pom.xml underneath. -> Finish.
- Wait for Importing Maven projects background job to finish
- Go to Workbench (upper right corner)
- If there will be Java problems don’t panic
- Window -> preferences -> Java -> Installed JREs -> Add -> Standard VM -> Directory for Java JDK (not JRE!) -> Finish. Choose jdk from list -> Apply.
- Root project (WeatherForecast) -> Run as Maven Install, it should output “[INFO] BUILD SUCCESS” at the end
- If there are still red markers: Project -> Clean
- Go to com.pgs.ws.rest.Application.java class in rest module, Run as -> Java Application
- Output should start to appear on console, and at the end, you should get a line like: “ : Started Application in 12.208 seconds (JVM running for 12.852)”
- MySQL Connections -> Local instance MySQL57
- File -> New query tab
- Create schema by executing statement: “CREATE DATABASE forecast DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;”
- Schema name should match property: “spring.datasource.url” in project file: “WeatherForecast\database-access\src\main\resources\application.properties”, in this case “jdbc:mysql://localhost:3306/forecast”
- Create user by executing statement: “CREATE USER 'username'@'localhost' IDENTIFIED BY userpass;”
- User name and password should match properties “spring.datasource.username” and “spring.datasource.password” in the same file
- Grant the new user permissions to schema: “GRANT ALL ON forecast.* TO 'username'@'localhost';”
- Click refresh in Schemas and select forecast if it’s not visible yet
- File -> Run SQL script, select script from project: “WeatherForecast\database-access\src\main\resources\sql\mysql\ddl\V0__create_forecast_table.sql”, select forecast schema -> Run
- Download curl from https://curl.haxx.se/download.html
- From command line: curl -H "Content-type: application/json" http://localhost:8080/forecast/Berlin/
- It should output something like: {"location":"Berlin","temperature":278}
- Postman might be more convenient alternative to curl, download and install from https://www.getpostman.com/docs/introduction (requires Google Chrome browser)
- In New tab -> Enrer request URL: “http://localhost:8080/forecast/Berlin/2016-03-03/”
- In headers select “Content-type” key and “application/json”
- Hit send, and you should get the same output as in Curl