- Fork SimpleJ2EEProject
- Create git branch "newServlet"
- Create HttpServlet and map to "/" (use BaseHttpServlet which is in project) and commit changes
- Get instance of HelloWorldGenerator from context BaseHttpServlet.getBean() and print it in page (use htm page structure), commit
- Change HelloWorldGeneratorImpl hello text to "Hello world", commit
- Push changes to remote
- Checkout master
- Create new branch "newHelloText"
- Change HelloWorldGeneratorImpl hello text to "Hello visitor", commit
- Push changes to remote
- Checkout master
- Merge branch newHelloText to master, push
- Merge branch newServlet to master, push
- run "mvn package" and Deploy web-app.war to tomcat
- Connect to tomcat debug port
- create breakpoint in servlet
- Change hello text from debug to "broken Hello"
- Show result to lecture
- copy setenv.bat to {tomcatDir}/bin to enable debug port 8000
- to create war artifact run "mvn package" (maven should be installed and configured) (https://www.mkyong.com/maven/how-to-install-maven-in-windows/)
- Git lecture video https://www.youtube.com/watch?v=iJm0xflVz_8
- Lecture pptx files https://drive.google.com/drive/folders/0B4OuEuZP2SJYUTR4RjNNeXI3ZGM?usp=sharing
- Contact me andreydemosoft@gmail.com
- telegram chat https://t.me/joinchat/EY_wXQx2hyoLgYSerz8_qw
Simple java 2 EE project fro TI karazin java course
- Set up GitHub account
- Import project
- Set up simple web project (1 servlet)
- Make commit/push
- Make branch/merge
- Debug Servlet"
-
Dowload and Import new spring project
- Open https://start.spring.io/
- Select maven spring boot project with version 1.5.8
- Search for dependency named "Web" and add it
- Click Generate project
- Unzip
- Import as new maven project
- Wait when all dependecies will be resolved
- Check tha you have DemoApplication.java file
-
Create Controller
- Check required dependencies in pom.xml (wait for resolving dependencies after any pom.xml updates before start application)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency>
- Create class NewController
- Mark class with @RestController Annotation
- Create Method
public String index(){ return "<html><body><h1>Hello</h1></body></html>"; }
- Mark method with following annotation
@RequestMapping(value = "/index.html", method = RequestMethod.GET)
- Check that you have right imports
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;
- Run DemoApplication.main()
- Check result http://localhost:8080/index.html
- Check required dependencies in pom.xml (wait for resolving dependencies after any pom.xml updates before start application)
-
Spring boot configuration
- Find file /src/main/resources/application.properties
- Put following config
server.port=8081
- Chek results on new port
- Add following config to /src/main/resources/application.properties
custom.message=Hello My friend
- Add Filed and constructor to your controller
private final String msg; public NewController(@Value("${custom.message}") String msg) { this.msg = msg; }
- Pay Atentions on following code in construictor. (It is injection of value from config files)
@Value("${custom.message}") String msg
- Change your method to dispaly variable "msg" on yopur page
@RequestMapping(value = "/index.html", method = RequestMethod.GET) public String index(){ return "<html><body><h1>" + msg + "</h1></body></html>"; }
- Check results