Angular and SpringBoot both have way too much of magic, if you are one who like to be in controll of their code, then check > out my project on pure Java 11 (With Modules), Jersey and Vue.JS for UIWebApp with Java 11, Jersey and VueJS
Application to demonstrate various parts of a service oriented RESTfull application.
Allow couple of minutes to let the instance start
Component | Technology |
---|---|
Frontend | Angular 5 |
Backend (REST) | SpringBoot (Java) |
Security | Token Based (Spring Security and JWT ) |
REST Documentation | Swagger UI / Springfox and ReDoc |
REST Spec | Open API Standard |
In Memory DB | H2 |
Persistence | JPA (Using Spring Data) |
Client Build Tools | angular-cli, Webpack, npm |
Server Build Tools | Maven(Java) or Gradle |
PROJECT_FOLDER
│ README.md
│ pom.xml
│ build.gradle
└──[src]
│ └──[main]
│ └──[java]
│ └──[resources]
│ │ application.properties #contains springboot cofigurations
│ │ schema.sql # Contains DB Script to create tables that executes during the App Startup
│ │ data.sql # Contains DB Script to Insert data that executes during the App Startup (after schema.sql)
│ └──[public] # keep all html,css etc, resources that needs to be exposed to user without security
│
└──[target] #Java build files, auto-created after running java build: mvn install
│ └──[classes]
│ └──[public]
│ └──[webui] #webui folder is created by (maven/gradle) which copies webui/dist folder
│ #the application.properties file list webui as a resource folder that means files can be accesses http://localhost/<files_inside_webui>
│
└──[webui]
│ package.json
│ angular-cli.json #ng build configurations)
└──[node_modules]
└──[src] #frontend source files
└──[dist] #frontend build files, auto-created after running angular build: ng -build
Ensure you have this installed before proceeding further
This is an RESTfull implementation of an order processing app based on Northwind database schema from Microsoft.The goal of the project is to
Backend
Frontend
Build
I have included an in-memory database for the application. Database schema and sample data for the app is created everytime the app starts, and gets destroyed after the app stops, so the changes made to to the database are persistent only as long as the app is running
Creation of database schema and data are done using sql scripts that Springs runs automatically.To modify the database schema or the data you can modify schema.sql and data.sql which can be found at /src/main/resources
Security is enabled by default, to disable, you must comment this line in src/main/java/com/config/SecurityConfig.java
When security is enabled, none of the REST API will be accessesble directly.
To test security access http://localhost:9119/version
API and you should get a forbidden/Access denied error.In order to access these secured API you must first obtain a token. Tokens can be obtained by passing a valid userid/password
userid and password are stored in H2 database. To add/remove users, modify the data.sqlcouple of valid users and their passwords are demo\demo
and admin\admin
To get a token call POST /session
API with a valid userid and password.for example you may you can use the folliwing curl command to get a token
curl -X POST --header 'Content-Type: application/json' -d '{ "username":"demo", "password":"demo" }' 'http://localhost:9119/session'
the above curl command will return you a token, which should be in the format of xxx.xxx.xxx
. This is a JSON web token format.You can decode and validate this token at jwt.io wesite. Just paste the token there and decode the information.to validate the token you should provide the secret key which is mrin
that i am using in this app.
after receiving this token you must provide the token in the request-header of every API request. For instance try the GET /version
api using the belowcurl command (replace xxx.xxx.xxx with the token that you received in above command) and you should be able to access the API.
curl -X GET --header 'Accept: application/json' --header 'Authorization: xxx.xxx.xxx' 'http://localhost:9119/version'
Code for frontend is allready compiled and saved under the webui/dist
when building the backend app (using maven) it will pickup the code from webui/dist
. However if you modified the frontend code and want your changes to get reflected then you must build the frontend
# Navigate to PROJECT_FOLDER/webui (should contain package.json )
npm install
# build the project (this will put the files under dist folder)
ng build --prod --aot=true
# Maven Build : Navigate to the root folder where pom.xml is present
mvn clean install
#OR
# Gradle Build : Navigate to the root folder where build.gradle is present
gradle build
# Start the server (9119)
# port and other configurations for API servere is in [./src/main/resources/application.properties](/src/main/resources/application.properties) file
# If you build with maven jar location will be
java -jar ./target/app-1.0.0.jar
# If you build with gradle jar location will be
java -jar ./build/libs/app-1.0.0.jar
Cpmponent | URL | Credentials |
---|---|---|
Frontend | http://localhost:9119 | demo/demo |
H2 Database | http://localhost:9119/h2-console | Driver:org.h2.Driver JDBC URL: jdbc:h2:mem:demo User Name: sa |
Swagger (API Ref) | http://localhost:9119/swagger-ui.html | |
Redoc (API Ref) | http://localhost:9119/redoc/index.html | |
Swagger Spec | http://localhost:9119/api-docs |
To get an authentication token
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"username": "demo", "password": "demo" }' 'http://localhost:9119/session'
or POST the username and password to http://localhost:9119/session
after you get the authentication token you must provide this in the header for all the protected urls
curl -X GET --header 'Accept: application/json' --header 'Authorization: [replace this with token ]' 'http://localhost:9119/version'
To get an authentication token
Thank you to all our backers!
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
POI生成Word文档 使用POI XWPF生成Word文档,引入POI: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.0</version> </dependency> 项目中经常从Word模板生成文档,下面示例演示了替换文档内
angular-spring-data-rest An AngularJS module with an additional interceptor which eases the work with a Spring Data REST backend. See how it works If you want to see the module in action, then check o
我有一个简单的springboot应用程序和一个Rest api。我想验证请求参数不为null/空。我将json转换成一个java对象,并从这里开始验证它们是否包含所有必需的字段,并且不为null或不为空。(对象没有保存到db)我目前正在使用javax验证方法,但是没有成功。 我还有一个包含的要素类,我需要验证(所有字段均为必填字段,而不是空或空)
问题内容: 我正在尝试将AngularJS等客户端框架与Django结合起来。令我真正困惑的一件事是路由和REST问题。 我一直在尝试在线阅读很多相关内容,但是文档非常有限,尤其是在Django与Angular结合使用的情况下(这里或那里的小片段)。我知道我需要添加一个类似TastyPie的REST框架,以便在我的应用程序中创建一个健壮的REST接口,以便Angular插入并获取资源。 但是,我对
我正在使用SpringBoot构建REST API,这个REST API接受来自消费者的多个数据,例如empId、empName、empDept。在我当前的代码中,我使用注释从请求中访问查询参数值。但是我发现我们也可以使用从URI的占位符中获取数据。 想知道使用或其他方法获取多输入请求的最佳实践是什么?
我试图用以下框架构建一个Web应用程序: 前端有棱角的JS 我想使用Spring Security性来验证从Angular JS到Spring REST Web服务的所有请求。我还需要管理会话超时/记住密码等(web应用中登录功能的所有典型功能) 我已经阅读了数百篇文章,试图找出如何做到这一点,但没有一篇完全符合我的要求。 非常感谢您在这方面提供的任何帮助(内联答案或外部链接),以及详细的步骤。
我在Heroku上开发了一个简单的CRUD Springboot后端。 null 非常感谢任何帮助