Coder Social home page Coder Social logo

dsyer / spring-boot-angular Goto Github PK

View Code? Open in Web Editor NEW
364.0 28.0 147.0 3.24 MB

Quick tutorial on how to create a Spring Boot app with Angular front end using Maven and modern front end tooling

Home Page: https://github.com/dsyer/spring-boot-angular

Shell 1.94% TypeScript 62.72% JavaScript 14.96% HTML 5.27% CSS 0.45% Java 14.66%

spring-boot-angular's Introduction

Creating a New Application with Spring Boot and Angular

Spring Boot works great as a back end for an Angular application but it can be difficult to get the ball rolling. Most Spring users are comfortable with Java and the tools that are used to create and build the backend server. The front end can be written with plain old JavaScript as long as it is relatively simple, and you are willing to search for the rare examples and tutorials in this style. But these days you are much more likely to find documentation and tutorials that use tools like Typescript, node.js, npm and the Angular CLI.

This article shows you how to do that and keep your Spring Boot application intact. Much of the advice would apply equally well to other front end frameworks (anything that can be built using npm or similar). We use Maven, but similar tools are available for Gradle users. The goal is to have a single application that has Spring Boot and Angular, that can be built and developed by anyone who has knowledge of either ecosystem, and does not feel awkward or unidiomatic to either.

Create a Spring Boot Application

Whatever you normally do to create a new Spring Boot application, do that. For example you could use your IDE features. Or you could do it on the command line:

$ curl start.spring.io/starter.tgz -d dependencies=web | tar -zxvf -
$ ./mvnw install

Now we’ll take that application and add some Angular scaffolding. Before we can do anything with Angular, we have to install npm.

Install Npm Locally

Installing npm is fraught with issues, including but not limited to how to get it working as part of your build automation. We are going to use the excellent Maven Frontend Plugin from Eirik Sletteberg. The first step is to add it to our pom.xml:

pom.xml
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.12.0</version>
            <configuration>
                <nodeVersion>v16.13.1</nodeVersion>
            </configuration>
            <executions>
                <execution>
                    <id>install-npm</id>
                    <goals>
                        <goal>install-node-and-npm</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

and then

$ ./mvnw generate-resources
$ ls node*

Loads of stuff has been installed in the top level directory. Once the downloaded files are cached in your local Maven repository, it won’t take long to run this for every build.

Install Angular CLI

To build an Angular app these days it really helps to use the CLI provided by the Angular team. We can install it using the npm that we just got using the plugin. First create a convenient script to run npm from the local installation (in case you have others on your path):

$ cat > npm
#!/bin/sh
cd $(dirname $0)
PATH="$PWD/node/":$PATH
node "node/node_modules/npm/bin/npm-cli.js" "$@"
$ chmod +x npm

and then run it to install the CLI:

$ ./npm install @angular/cli
Note
Windows users can find a similar looking npm.cmd script in node/node_modules/npm/bin. If you copy it to the root of the project, and edit to match the local paths, you can use it in the same way.

Then create a similar wrapper for the CLI itself, and test it quickly:

$ cat > ng
#!/bin/sh
cd $(dirname $0)
PATH="$PWD/node/":"$PWD":$PATH
node_modules/@angular/cli/bin/ng.js "$@"
$ chmod +x ng
$ ./ng --version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
           |___/
Angular CLI: 13.0.4
Node: 16.13.1
OS: linux x64
...
Note
Windows user can try the same trick with ng.cmd as with npm.cmd to get a local command to run the Angular CLI.

Create an Angular App

The Angular CLI can be used to generate new application scaffolding, as well as other things. It’s a useful starting point, but you could at this point grab any existing Angular app and put it in the same place. We want to work with the Angular app in the top level directory to keep all the tools and IDEs happy, but we also want make it look like a regular Maven build.

Create the app with the CLI:

$ ./ng new client # add --minimal here if you want to skip tests

and then move it into the root of the project:

$ cat client/.gitignore >> .gitignore
$ rm -rf client/node* client/src/favicon.ico client/.gitignore client/.git
$ cp -rf client/* .
$ cp client/.??* .
$ rm -rf client
$ sed -i -e 's,dist/client,target/classes/static,' angular.json

We discarded the node modules that the CLI installed because we want the frontend plugin to do that work for us in an automated build. We also edited the angular.json (a bit like a pom.xml for the Angular CLI app) to point the output from the Angular build to a location that will be packaged in our JAR file.

Building

Add an execution to install the modules used in the application:

<execution>
    <id>npm-install</id>
    <goals>
        <goal>npm</goal>
    </goals>
</execution>

Install the modules again using ./mvnw generate-resources and check the result (the versions will differ for you).

$ ./ng version
    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
           |___/
Angular CLI: 13.0.4
Node: 16.13.1
OS: linux x64
Angular: 13.0.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect       0.1300.4
@angular-devkit/build-angular   13.0.4
@angular-devkit/core            13.0.4
@angular-devkit/schematics      13.0.4
@angular/cli                    13.0.4
@schematics/angular             13.0.4
rxjs                            7.4.0
typescript                      4.4.4

At this point, the tests work:

$ ./ng test
Generating browser application bundles (phase: setup)...09 12 2021 13:57:18.567:WARN [karma]: No captured browser, open http://localhost:9876/
09 12 2021 13:57:18.576:INFO [karma-server]: Karma v6.3.9 server started at http://localhost:9876/
09 12 2021 13:57:18.576:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
09 12 2021 13:57:18.590:INFO [launcher]: Starting browser Chrome
✔ Browser application bundle generation complete.
09 12 2021 13:57:21.749:WARN [karma]: No captured browser, open http://localhost:9876/
09 12 2021 13:57:21.797:INFO [Chrome 94.0.4606.71 (Linux x86_64)]: Connected on socket Fh4AKRcSDz0TEUkyAAAB with id 93745390
✔ Browser application bundle generation complete.
Chrome 94.0.4606.71 (Linux x86_64): Executed 3 of 3 SUCCESS (0.133 secs / 0.119 secs)
TOTAL: 3 SUCCESS

and if you add this as well:

    <execution>
        <id>npm-build</id>
        <goals>
            <goal>npm</goal>
        </goals>
        <configuration>
            <arguments>run-script build</arguments>
        </configuration>
    </execution>

then the client app will be compiled during the Maven build.

Stabilize the Build

If you want a stable build you should put a ^ before the version of @angular/cli in your package.json. It isn’t added by default when you do ng new, but it protects you from changes in the CLI. Example:

package.json
...
"devDependencies": {
    "@angular/cli": "^13.0.4",
...

Development Time

You can build continuously with

$ ./ng build --watch

Updates are built (quickly) and pushed to target/classes where they can be picked up by Spring Boot. Your IDE might need to be tweaked to pick up the changes automatically (Spring Tool Suite does it out of the box).

That’s it really, but we can quickly look into a couple of extra things that will get you off the ground quickly with Spring Boot and Angular.

VSCode

Microsoft VSCode is quite a good tool for developing JavaScript applications, and it also has good support for Java and Spring Boot. If you install the "Java Extension Pack" (from Microsoft), the "Angular Essentials" (from Jon Papa) and the "Latest TypeScript and JavaScript Grammar" (from Microsoft) you will be able to do code completion and source navigation in the Angular app (all those extensions and discoverable from the IDE). There are also some Spring Boot features that you need to download and install (in Extensions view click on top right and choose Install from VSIX…​) at http://dist.springsource.com/snapshot/STS4/nightly-distributions.html.

What VSCode doesn’t have currently is automatic detection of npm build tools in the project itself (and ours is in . so we need it). So to build from the IDE you might need to add a .vscode/tasks.json something like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "ng-build",
            "type": "shell",
            "command": "./ng build"
        },
        {
            "label": "ng-watch",
            "type": "shell",
            "command": "./ng build --watch"
        }
    ]
}

With that in place your Tasks→Run Task…​ menu should include the ng-watch option, and it will run the angular build for you and re-compile if you make changes. You could add other entries for running tests.

Adding Bootstrap

You can add basic Twitter Bootstrap features to make the app look a bit less dull (taken from this blog):

$ ./npm install bootstrap --save

and update styles.css to add the new content:

styles.css
@import "~bootstrap/dist/css/bootstrap.css";

Basic Angular Features

Some basic features are included in the default scaffolding app, including the HTTP client, HTML forms support and navigation using the Router. All of them are extremely well documented at angular.io, and there are thousands of examples out in the internet of how to use those features.

As an example, lets look at how to add an HTTP Client call, and hook it up to a Spring @RestController. In the front end app-root component we can add some placeholders for dynamic content:

app.component.html:
<div style="text-align:center"class="container">
  <h1>
    Welcome {{title}}!
  </h1>
  <div class="container">
    <p>Id: <span>{{data.id}}</span></p>
    <p>Message: <span>{{data.content}}</span></p>
  </div>
</div>

so we are looking for a data object in the scope of the component:

app.component.ts:
import { Component } from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'Demo';
  data = {}  as any;
  constructor(private http: HttpClient) {
    http.get('resource').subscribe(data => this.data = data);
  }
}

Notice how the AppComponent has an HttpClient injected into its constructor. In the module definition we need to import the HttpClientModule as well, to enable the dependency injection:

app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

In our Spring Boot application we need to service the /resource request and return an object with the right keys for the client:

DemoApplication.java:
@SpringBootApplication
@Controller
public class DemoApplication {

  @GetMapping("/resource")
  @ResponseBody
  public Map<String, Object> home() {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("id", UUID.randomUUID().toString());
    model.put("content", "Hello World");
    return model;
  }

...

}

If you look at the source code in Github you will also notice that there is a test for the backend interaction in app.component.spec.ts (thanks to this Ninja Squad blog). The pom.xml has been modified to run the Angular e2e tests at the same time as the Java tests.

Conclusion

We have created a Spring Boot application, added a simple HTTP endpoint to it, and then added a front end to it using Angular. The Angular app is self-contained, so anyone who knows the tools can work with it from its own directory. The Spring Boot application folds the Angular assets into its build and a developer can easily update and test the front end from a regular IDE by running the app in the usual way.

spring-boot-angular's People

Contributors

angular-cli avatar dsyer avatar praveen-erramilli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-boot-angular's Issues

ng test failing

Following this article is not easy by itself but I did and once I issue ng test, I get

mymac > ~/devwork/UiSpringAngular/client > master > ng test

Node packages may not be installed. Try installing with 'npm install'.
Could not find the '@angular-devkit/build-angular:karma' builder's node package.

I am not surprised it is failing since in step before that, the instructions are saying to delete node_modules folder from client app generated within the Spring Boot project

I already had Angular CLI installed on my mac, so I skipped that part in the instructions.

My project structure now looks like

UIApp
  |-client   // deleted its node_modules, favicon.ico, .gitignore as per instructions
       |+src
       |-angular.json  // modified its output path to "outputPath": "target/classes/static", as per instructions
       |-...
  |+node
  |-src
      |+main
      |+test
  |-pom.xml

Upgrade node version

Issue

The Node version used is very old, it is necessary to update to a newer one.

<configuration>
    <nodeVersion>v9.11.2</nodeVersion>
</configuration>

When running:

./ng --version

You get:

Node.js version v9.11.2 detected.
The Angular CLI requires a minimum Node.js version of either v12.14 or v14.15.

Please update your Node.js version or visit https://nodejs.org/ for additional instructions.

Solution

  1. Delete node, node_modules and everything related to node.
  2. Update pom.xml:
<configuration>
    <nodeVersion>v14.18.1</nodeVersion>
</configuration>
<!--or choose another compatible version here: https://nodejs.org/dist/-->
  1. Setup everything again.

Note: I don't know if it's an error or a warning because I just deleted the folders and reinstalled using a newer version.

npm needs to be updated to 8.9 or higher

You are running version v8.8.1 of Node.js, which is not supported by Angular CLI v6.
The official Node.js version that is supported is 8.9 and greater.

I got this error when trying to run ng.

angular build broken after removing the content and id attributes from the greeting object in app.component.ts

Thanks for a great series of tutorials!

Not a Spring issue, but currently removing the content and id attributes from the greeting object in app.component.ts breaks the angular build.

$ npm run-script build

> [email protected] build /Users/aram/Projects/SpringDemos/spring_angular_demo
> ng build --prod

Date: 2018-02-22T04:03:54.694Z                                                     
Hash: dbe61dd8d182e0368dec
Time: 2653ms
chunk {scripts} scripts.e2cc764d74d6cb8d1c42.bundle.js (scripts) 123 kB [initial] [rendered]
chunk {0} styles.cc6c20b8b9ca75033724.bundle.css (styles) 116 kB [initial] [rendered]
chunk {1} polyfills.997d8cc03812de50ae67.bundle.js (polyfills) 84 bytes [initial] [rendered]
chunk {2} main.ee32620ecd1edff94184.bundle.js (main) 84 bytes [initial] [rendered]
chunk {3} inline.318b50c57b4eba3d437b.bundle.js (inline) 796 bytes [entry] [rendered]

ERROR in src/app/app.component.html(9,18): : Property 'id' does not exist on type '{}'.
src/app/app.component.html(10,23): : Property 'content' does not exist on type '{}'.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `ng build --prod`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/aram/.npm/_logs/2018-02-22T04_03_54_720Z-debug.log

My environment:

Angular CLI: 1.7.0
Node: 8.8.1
OS: darwin x64
Angular: 5.2.5
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.0
@angular-devkit/build-optimizer: 0.3.1
@angular-devkit/core: 0.3.1
@angular-devkit/schematics: 0.3.1
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.0
@schematics/angular: 0.3.1
@schematics/package-update: 0.3.1
typescript: 2.5.3
webpack: 3.11.0

npm local install

In readme you are installing npm locally using a script ... which uses the locally installed npm; there must be something wrong :-)

Update Node version in POM file

As of today, Angular CLI v6 requires NodeJS v8.9+ but in the instructions in the README.md, inside the tag you are using v8.8.1 which was causing me problems.

Should change to the latest stable NodeJS version which is v8.11.1

EDIT: Also thanks to another user, the README.md should be updated because the .angular-cli.json file has been renamed to angular.json. Also should update de Angular CLI version to the latest which is v6.0

Windows setup ??

Hello, thanks for your work, it would be great if there was a section about configuration under windows

Angular routing

The angular routing doesn't work and is taken over by spring mappings. Try to navigate to login page by directly typing localhost:8080/login or refresh the browser at any page, it will give 404. I tried using the redirect `return "redirect:/" but it prints the string in the browser. Can you please help with this?

Use yarn over npm

Yarn is much better than npm.

You should include in the pom.xml

<build>
    ...
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <version>1.6</version>
            <configuration>
                <nodeVersion>v8.8.1</nodeVersion>
            </configuration>
            <executions>
                <execution>
                    <id>install node and yarn</id>
                    <goals>
                        <goal>install-node-and-yarn</goal>
                    </goals>
                    <configuration>
                        <nodeVersion>v8.9.4</nodeVersion>
                        <yarnVersion>v1.3.2</yarnVersion>
                    </configuration>
                </execution>

                <execution>
                    <id>yarn install</id>
                    <goals>
                        <goal>yarn</goal>
                    </goals>
                    <configuration>
                        <arguments>install</arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
</plugins>
</build>

Then as you create a local npm executable you can create a local yarn using this nippet

#!/bin/sh
cd $(dirname $0)
"node/yarn/dist/bin/yarn" "$@"

all ./npm install can now be replaced with ./yarn add.

Yarn generates a package.json when it installs first type angular-cli then the ng tool refuses to create the new app; so you should rename package.json before calling ./ng new client.

The test block in pom.xml should appear as:

                <execution>
                    <id>yarn-build</id>
                    <goals>
                        <goal>yarn</goal>
                    </goals>
                    <configuration>
                        <arguments>run build</arguments>
                    </configuration>
                </execution>

BTW in your readme the block

		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>

is repeated twice.

java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

I tried ./mvnw generate-resources and i got this error in Ubuntu 18.04,

Exception in thread "main" javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1964)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1921)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1904)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1420)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.apache.maven.wrapper.DefaultDownloader.downloadInternal(DefaultDownloader.java:73)
at org.apache.maven.wrapper.DefaultDownloader.download(DefaultDownloader.java:60)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:64)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:121)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.validator.PKIXValidator.(PKIXValidator.java:91)
at sun.security.validator.Validator.getInstance(Validator.java:179)
at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:312)
at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:171)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:184)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1596)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
... 11 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
at java.security.cert.PKIXParameters.(PKIXParameters.java:120)
at java.security.cert.PKIXBuilderParameters.(PKIXBuilderParameters.java:104)
at sun.security.validator.PKIXValidator.(PKIXValidator.java:89)
... 23 more

and I found this solution,

First remove conflicting packages:
sudo apt-get remove --purge openjdk* java-common default-jdk
sudo apt-get autoremove --purge
Check weather you successfully removed all related packages by:
sudo update-alternatives --config java
The system shall prompt you there is no Java available to config, otherwise this workaround fails.
Then reinstall required packages:
sudo apt-get install openjdk-8-jdk
https://stackoverflow.com/questions/6784463/error-trustanchors-parameter-must-be-non-empty/25188331#25188331

then add JAVA_HOME.

Open /etc/environment in any text editor like nano or gedit and add the following line:
JAVA_HOME="/usr/lib/jvm/open-jdk"
(java path could be different)
Use source to load the variables, by running this command:
source /etc/environment
Then check the variable, by running this command:
echo $JAVA_HOME
( https://askubuntu.com/questions/175514/how-to-set-java-home-for-java )

BUILD FAILURE when trying to run with mvn spring:boot run

I'm trying to run the application with mvn spring:boot run. Getting error as below :

[WARNING] The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.eclipse.m2e:lifecycle-mapping:1.0.0: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failure to find org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
org.apache.maven.plugin.PluginResolutionException: Plugin org.eclipse.m2e:lifecycle-mapping:1.0.0 or one of its dependencies could not be resolved: Failure to find org.eclipse.m2e:lifecycle-mapping:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
.
.
.
[ERROR] No plugin found for prefix 'spring' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/aniruddhmishra/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException: No plugin found for prefix 'spring' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/aniruddhmishra/.m2/repository), central (https://repo.maven.apache.org/maven2)]

Include Bootstrap CSS in `src\styles.css`

I'm just skimming through your project: spring-boot-angular. I noticed that you indicate to include Bootstrap library like this:

"styles": [
    "styles.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],

I don't know about Bootstrap 3, but with Bootstrap 4 and angular 4 / 5, my experience is that this will only work in dev mode. Compilation will be a problem.

Importing bootstrap.css in src\styles.css like this

@import "~bootstrap/dist/css/bootstrap.css";

will work in all cases.

I have posted this stack about it.

How to build the App

Hi, first of all thanks for the detailed guide!

I am tring to build the app after following the instructions, but it seems there are many different ways to build it.

I can build the whole app (front + back) like this:
$ ./mvnw spring-boot:run
And I'd have it running at localhost:8080. To see the generated UUID and the greeting message I have to move to localhost:8080/resource

I can also build only the front like this:
$ ./npm start
or
$ ./ng serve
or
$ ./ng build # optionally with --watch
And I'd get the front running at localhost:4200
I don't understand why when loading localhost:4200 I get a different page with the Angular logo and some links to the Angular documentation and Angular blog.
If I run the app with ./mvnw spring-boot:run I can only see a JSON with the ID and the greeting message when loading localhost:8080/resource without any index.html or anything like that.

I suppose I have to always build the app with the mvn command but I am confused about wheter I am doing it wrong because I'm not seeing neither the ID or the greeting message when executing ./ng build

I'm plannign to have the SPA hosted at www.example.com and the Spring backend API at something like www.example.com/api so the front and the back are in the same domain but different directories but somehow I think I am doing something wrong or it just can't be like that, any tips are welcome!!

Thanks!

Test backend

In order to complete your demo I think it sould be better to add src/main/client/proxy-config.json

{
  "/resource": {
    "target": "http://localhost:8080",
    "secure": false
  }
}

and then modify src/main/package.json so that proxy config is used when runnung the start script:

  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy-config.json",
    ....

so you can run src/main/client/yarn start or src/main/client/ng serve --proxy-config proxy-config.json then start the backend in a new terminal mvn spring-boot:run and access http://localhost:4200 (or either port the Live Development Server is bound to).

Could the guide work on MACOS

I do everything strictly follow the guide, but I get this, my os is version 10.13.4(Hign Sierra)

Angular CLI: 6.0.8
Node: 8.11.2
OS: darwin x64
Angular: error
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

What are polyfills?

Hi dsyer,
There is no issue here, a query to help me understand angular in a better way.
Thank you for the code. Helping me learn faster.

What are polyfills? Why do we need them?
I see that there are browser polyfills as well as App polyfills. But why do we need them.

Can you please give a brief on the fundamentals of polyfills in current context, it would be great.

Regards,
Anand Karadi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.