Angular Spring Boot Packaging Issue - spring

I have the current project structure for a spring boot angular project
+--app-ui
|--+--src
|--+--dist
|--app-backend
|--+--src
|--+--+--main
|--+--+--+--resources
|--+--+--+--+--static
|--+--+--+--java
app-ui contains the angular 6 code app backend contains the spring boot code. Now everytime I build app-ui i want the dist folder contents in app-ui to be copied to app-backend/src/main/resources/static
In order to do that I have added these lines in the angular build
"predeploy": "rimraf ../app-backend/src/main/resources/static/ && mkdirp ../app-backend/src/main/resources/static",
"deploy": "copyfiles -f dist/** ../app-backend/src/main/resources/static/
This creates the static folder inside Spring boot project but it doesn't copy the files and folders inside dist folder.

If you are using AngularCLI (with an angular.json file), simply change the outputPath property to specify your desired static directory.
"outputPath": "../app-backend/src/main/resources/static"

I tried this way for integrating my angular app with spring-boot so the static code is atleast in spring boot app path. But I still couldn't see user interface when my spring app is running on port 8080.
Not sure if I'm missing something but majority of my frontend code that is; ng components .ts, .html and .css files are in frontend/src dir, which I didn't move anywhere. Any suggestions?

Related

How to make #SpringBootTest use application.properties from external config folder (inside project root)?

I have a multi-module Spring Boot Gradle project (Kotlin) with the following directory structure.
root
|- domain (Module containing entities and interfaces)
|- application (Spring boot Kotlin application)
|- src/main
|- kotlin (app sources)
|- resources
|- application.properties (default config)
|- src/test/kotlin/long/package/name/ApplicationTests.kt
|- build.gradle.kts (and also gradle folder)
|- config
|- application.properties (config to override classpath properties)
|- build.gradle.kts (and settings.gradle.kts and other gradle folder)
When I run the Application.kt file, it is able to pick up this file (both with IDE and gradle), and it runs successfully.
Since my config folder is outside my application folder, running my ApplicationTests.kt results in the error below. The output is same when running through IDE (IntelliJ) run button and ./gradlew clean test.
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection
I am expecting the tests to find the application.properties file inside the config folder. How can I register my config/application.properties so that I can keep it separate from my classpath:application.properties?
UPDATE:
I tried adding the following copy task to gradle.
tasks.create("copy", Copy::class.java) {
from("../config")
into("$buildDir/resources/main")
}
tasks.named("test").configure {
dependsOn("copy")
}
This enables me to overwrite the application.properties from config folder (meaning any property not added in config/app.prop is no longer present). Test runs successfully now (if I add all entries from classpath properties to config/app.props). How can I merge the contents of these two properties files inside application/build.gradle.kts?
If you want to override your application.properties with an external application.properties, you can copy the external file to build/classes directory using Gradle and append a profile name, like application-ext.properties. Then, activate default and ext profiles using spring.profiles.active.
Another option would be to use Spring Config server, but that may be overkill for this simple task.
By default, Spring will look in your current working directory for the directory named, config. As you've noted, you're not executing the application in the directory containing the config directory. You can override where Spring looks for this config folder with the -Dspring.config.location option or via the environment variable, SPRING_CONFIG_LOCATION
If your config directory is located at /opt/myconfigs/config, you would start your service with -Dspring.config.location=/opt/myconfigs/config. Another option is to export SPRING_CONFIG_LOCATION=/opt/myconfigs/config and start your app without any additional JVM options.
If you're running tests in the application directory, then the config folder would be one level up from the current working directory. Annotating your tests with
#TestPropertySource(properties = "spring.config.location=../config/,classpath:/application.properties") would load the application.properties from both the config folder and the src/main/resources folder, properties in the config props would override properties in the local application properties.
The same thing can be achieved with the VM argument of -Dspring.config.location=classpath:/application.yml,file:../config/, here order is important.

projects_default.yml file in thorntail

Thorntail generator does not generate any project_defaults.yml file in project structure. No resources folder also seen.Should we manually place this file to configure project properties?
Note : I am new to thorntail.
Yes, you need to create a file project-defaults.yml inside src/main/resources.

Spring Boot how to add another resources folder in test folder

Is it possible to add another resources folder in test folder, which will also be on the classpath?
I need it because I don't want to add application-test.properties file in default resources folder because it belongs in test folder.
I tried to add folder manually but it does not work.
I soloved this problem, in Intellij IDEA by:
Right clicking on the project -> Projectu structure,
and I marked newlycreated folder as Resources file.
It is gradle project or maven? If you have gradle just add the line below to the build.gradle file:
ext {
resourcesDir = projectDir.path + "/other/resources"
}
where the /other/resources is your dedicated resource folder

Best practice for configuration in multi maven projects

given the following spring boot application layout:
app
--api
--component
--data
--xyz
libs
--lib1
--lib2
Each one is a seperate maven project where "app" contains the spring bootstrap class. Other modules are maven dependencies that are used within the application.
Each modules comes with its own profiled property file (application-dev.properies, application-qa.properties...)
What is the best way to consolidate now all property files within the application?
My proposal for consolidation:
Each module defines own profile, for example:
application-DEV-lib1.properties
application-QA-lib1.properties
application-DEV-lib2.properties
application-QA-lib2.properties
app defines profiles DEV and QA:
application-DEV.properties
spring.profiles.include=DEV-lib1,DEV-lib2
aaa=123
...
application-QA.properties
spring.profiles.include=QA-lib1,QA-lib2
aaa=456
...

Grails 3 - Angular template asset pipeline not bundling converted js files into application.js

I'm using Grails 3.1.10, angular-template-asset-pipeline 2.2.6, and asset-pipeline-gradle 2.8.2
It's tough for me to share config files as I work behind a firewall but the general issue is mostly similar to this https://github.com/bertramdev/grails-asset-pipeline/issues/336 (discussion started so i'll have to update question as things go)
Everything works fine under 'grails run-app' but when i run 'grails war':
the templates get correctly converted to js files
are exploded in tomcat under /webapps/myApp/assets
are not present in the application.js bundled result, therefore my app cannot find any html.
Any help appreciated.
I was required to put assets stuff in my application.groovy development environment for run-app to work, but i'm not sure if application.groovy is used when running 'grails war' .. i'm not a fan of having duplicate asset pipeline configurations. (build.gradle as well as application.groovy for each environment)
Thanks!
After i figured out which config file the configuraitons where coming from (run-app -> application.groovy, grails war -> build.gradle) ... i figured it out.
I got it to work with the following steps...
I moved all my templateUrl: 'file.html' calls to templateUrl: '/myApp/file.html' (directives and view code)
i set my "includePathInName= true"
i put my .tpl.html files in grails-app/assets/javascripts/myApp/templates
Important takeaway here is that grails-app/assets/javascripts/templates would not work for me.

Resources