I want to give my routes a prefix based on the folder in which they're in. For example, with this folder structure:
controllers/
├─ v1/
│ ├─ Controller.kt
├─ v2/
│ ├─ Controller.kt
I would like to get the following routes:
{host}/v1/{route}
{host}/v2/{route}
Currently, I need to set the 'prefix' on every controller separately:
#RestController
#RequestMapping("/v2/route")
Is there any way to achieve this in Spring with either custom annotations that allow a prefix (#RestControllerV1("/route")), or with some setting that just prefixes all files within a specific folder?
Related
I am migrating from libsass to dartscss, so moving from #import to #use. I have around 20 sites and the way I have my sites is to have one scss folder with all of my scss files and then have a site config per site that uses variables to override the default colours.
My site structure
scss/
├─ import.scss
├─ base/
│ ├─ _reset.scss
site1/
├─ scss/
│ ├─ settigns/
│ │ ├─ _config.scss
│ import.scss
In site1/scss/settings/_config.scss I have the following code:
$bgc: red;
And in my site1/scss/import.scss I have:
#use "settings/config" as *;
#use "../../scss/import.scss";
And finally in ../../scss/import.scss I have a simple test call to see if it works.
body {
background-color: $bgc;
}
When I view my site I get undefined variable and $bgc doesn't render. I would like to keep the structure I had before since I have many sites that share the same scss folder and all worked fine before when I used #import.
wanted to see if someone has ever had this issue before using spring boot.
I am trying to read a file that is inside the META-INF folder, from a class thats inside of the BOOT-INF folder
My jar structure looks like this:
META-INF/
├─ MANIFEST.MF
├─ maven/com.sample.manifestsample/
BOOT-INF/
├─ lib/
├─ classes/
│ ├─ com.sample.manifestsample/
│ │ ├─ configuration/
│ │ │ ├─ ManifestReader.class
The manifest file can look like so:
Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.2.2
Build-Jdk-Spec: 11
Implementation-Title: some-impl-title
Implementation-Version: 0.0.1-SNAPSHOT
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.sampletest.Application
Spring-Boot-Version: 2.6.7
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
and the Manifest reader class looks like so:
#PropertySource(value = "classpath:META-INF/MANIFEST.MF")
#Configuration
#Data
public class ManifestReader {
#Value("${Manifest-Version:not found}")
private String manifestVersion;
//... for simplicity lets assume this is all its mapping
}
Somehow the manifest file is not sourced properly when the application is deployed and executed as a jar.
Not sure what else to try, been pounding my head against the wall with this.
Edit: Was able to inspect the classpath index file and it seems that META-INF is not part of the classpath, so it wont be found. Not sure what the alternative is, was counting on producing this file and reading it at runtime from within spring boot
I'm generating a static website with Hugo.
Here's the structure of my content folder:
content/
└── post
├── post01
│ ├── image.xcf
│ ├── image.jpg
│ └── index.md
└── post02
├── image.xcf
├── image.jpg
└── index.md
Each of the posts has a .jpg files. These images are exported from my image editing program. To avoid confusion, I'm keeping the original working .xcf files from the image editing program in the same folder as the exported image, in case I need to edit an image in the future, and re-export it. But I don't want to publish those .xcf files to the server.
Is there a way to configure Hugo to exclude all files with .xcf extension when generating the static site?
Be aware that there's an open issue at GitHub that this feature might not work exactly as documented. It worked for me with Hugo 0.62.0 and your given directory and file structure.
As per the documentation, you can exclude content files with the ignoreFiles directive.
In your specific case, add the following to your config.toml (resp. YAML or JSON)
ignoreFiles = [ "\\.xcf$" ]
This question already has answers here:
How to use a module that is outside of "GOPATH" in another module?
(2 answers)
Closed 4 years ago.
I'm building an application using a 'Micro Service' architecture.
This means that I have different applications.
The truth is that some logic is in a 'shared' library.
See the following directory structure:
ROOT/
├── Service 1/
│ ├── src
│ ├──── app.go
├── Service 2/
│ ├── src
│ ├──── app.go
└── Lib/
├── Lib 1
│ ├── src
│ ├──── app.go
Service 1, Service 2, and Lib 1, are all initialized with the go mod command.
For Service 1, this resulted in a go.mod file with the following contents.
module github.com/kevin-de-coninck/datalytics/services/serviceOne
For Service 2, this resulted in a go.mod file with the following contents.
module github.com/kevin-de-coninck/datalytics/services/serviceTwo
For Lib 1, this resulted in a go.mod file with the following contents.
module github.com/kevin-de-coninck/datalytics/lib/libOne
The import statements of Service 1 contains a reference to the Lib 1
import (
"github.com/kevin-de-coninck/datalytics/lib/libOne"
)
However, when I try to build the application, the following output is showed:
go: finding github.com/kevin-de-coninck/datalytics/lib/libOne latest
go: finding github.com/kevin-de-coninck/datalytics/lib latest
go: finding github.com/kevin-de-coninck/datalytics latest
build github.com/kevin-de-coninck/datalytics/services/serviceOne/src:
cannot find module for path github.com/kevin-de-coninck/datalytics/lib/libOne
How can I resolve this issue so that i can use my LibOne package without making it public or whithout copying it across all the services?
Kind regards
After some fiddling around, I have found my answer.
It seems that the 'go.mod' and 'go.sum' file(s) should be placed in the 'src' directory.
After doing that, the application can be build and executed.
Base on this tutorial:
http://spring.io/guides/gs/serving-web-content/
I can use the thymeleaf to serve the view in the location
/src/main/resources/templates/
However, I have to put the static web contents (css, js) in another location:
/src/main/webapp/resources
And linking the resources in the hello.html like that:
<link href="resources/hello.css" />
<script src="resources/hello.js"></script>
The directory structure is:
└── src
└── main
└── java
└── hello.java
└──resources
└──templates
└──hello.html
└──webapp
└──resources
└──hello.js
└──hello.css
The problem is that the links of the static files are work when I run the web server. But if I open the html files in offline mode, the links are broken.
Could I move the static resource from
/src/main/webapp/resources
to:
/src/main/resources/templates/resources
The new directory structure would be like:
└── src
└── main
└── java
└── hello.java
└──resources
└──templates
└──hello.html
└──resources
└──hello.js
└──hello.css
I tried it but is doesn't work.
Try src/main/resources/static (or src/main/resources/public or src/main/resources/resources). All those are registered by Spring Boot autoconfig.
Define the mapping in your context like following -
<mvc:resources mapping="/templates/**"
location="classpath:/templates/" />
This will route everything that's hitting /template/ url to search for contents under your src/main/resources/templates/ folder.
In case you need tweaking in the url/prefix - adjust the mapping accordingly.