I have Spring + Angular APP.
I want to keep my directory structure as
ROOT
WEB-INF
UI-APP
index.html
css
js
But I don't want to access my application as domain/UI-APP.
I want UI-APP folder to be added / changed as ROOT.
Using welcome file is not the solution because
I don't want my Angular Project to be aware of UI-APP directory meaning I want all my js and html to use relative path.
ie ( if i rename UI-APP to View then also I don't want to change my html and js files. )
Is it possible without container specific way.
All i can think of is creating a servlet to handle all request and return content of file from UI-APP directory or may be Spring Servlet Dispatcher already has an option for it.
I want it to be as generic as possible.
Some Config in web.xml would be best.
Config in dispatcher servlet xml would also be ok.
tomcat, jetty specific configuration is the last resort.
Related
I have a Spring boot application deployed on a Weblogic server, and I want to add a Vue/vite frontend to it. I created a Vue project and then built it into static assets. I then placed the contents of the resulting Dist folder (index.html and assets folder) into src/main/resources/static of the Spring Boot project.
Then I generate the war file using Maven, and host that on Weblogic. The Spring Boot section of the app functions as normal, but when I navigate to weblogicurl/myapp/index.html- it is just a blank page rather than the complete frontend I'm expecting. Upon inspection, the blank index.html does have the standard Vue div element with id of "app", so weblogic is detecting and showing the static frontend. However, it is not able to pull any assets to actually display html or use the js - as it is 404ing when index.html tries to pull those built files.
I'm thinking that maybe it's because index.html is trying to pull the js and css assets from /weblogicurl/assets rather than /weblogicurl/myapp/assets but I'm not entirely sure as I'm unfamiliar with the intended structure of a Spring Boot Web app hosted on Weblogic. If that is the case, how would I resolve it? Though maybe it's some other issue, so any input would be greatly appreciated.
I'm assuming that your index.html has src URLs starting with / and that would cause weblogic to look in its default js assets folder. Alternatively, the src might include assets in the URL.
In any cases, you should update these URLs to be relative and correct after build aka remove the starting / and check path from html to js.
Turns out the problem was indeed that it was pulling assets from /weblogicurl rather than /weblogicurl/myapp.
Adding base: '/myapp/' to my vite.config.ts (or vue.config.js for non vite) resolved it.
I would like to ask where is the location where you can see the work directory of a spring boot / spring mvc applicaiton. Specifically I want to know Transpiled JSP files converted to java files.
I can see the class files inside the target directory, but cannot find the transpiled jsp files. Is there a class call where I can see it in my environment? Like System.getProperty("user.dir") or new java.io.File(".").getCanonicalPath(). I tried both and it only showed me the code path.
Also, I know the Eclipse Server path. But in spring boot, it does not seem to run using a server instance of tomcat. So the following path is not existing?
The following directory is also blank.
projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/
The base dir is set via the property server.tomcat.basedir, see: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html
The work dir is derrived from there by appending /work.
I have spring boot application and angular js project as two different modules.
The angular js contents ( files inside 'dist' folder) are converted as jar files and included as part of Spring boot application. The folder structure inside the jar is /static/**.
The jar appears inside the lib folder of the spring boot application.
Now when i try to access the application http://localhost:8080, i get 404 error.
It works fine, if i copy the "dist" folder content inside the /resources/static and create spring boot jar file.
Am i missing anything when the static contents are included as jar file. ?
Thanks in advance
I have a similar set up like you but using Angular 4. My Spring Boot version is 1.5.3.RELEASE.
My build is based on Maven with two modules. One for front-end (JAR) and one for backend (WAR), which references first module with Maven dependency mechanics.
Providing static content works out of the box. Since I'm using Spring Security I have to configure access rules for this resources. But this issue should be answered with a 401 and not 404.
Your angular JAR structure seems to be correct. Is your front-end build complete?
The lib folder with the front-end JAR is in my Spring Boot WAR on path /WEB-INF/.
Did you check if there is a bug connected with your used Spring Boot version?
#Moshe Arad #Raj In my understanding from https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot ,
the static contents can be in one of those mentioned locations. However, I myself is facing struggle in serving static content. I was working on spring-boot and angular-cli(6.1.5) based app. For deploy purpose, so that UI works on spring-boot port; I ran ng build. It generates files in src/main/resource/static (changed outputPath in angular.json to resources/static and create an empty dir static in resources) . But spring-boot didn't serve any angular content at 8080. Although index.html has <base href="/">, I thought to be more specific for it to pick/serve .js contents from static dir so I ran :
ng build --base-href / --deploy-url /static/ . This time the generated index.html has /static/runtime.js etc. in . But when accessing localhost:8080/ (right click -> inspect shows 200 response code) still doesn't show any UI content. But hitting localhost:8080/static/runtime.js shows 404 .
I believe there is more to do beyond just adding content to resources/static as probably tomcat is trying to serve it but somehow the content not being displayed. Because I do notice favicon icon (angular icon) on browser tab and the contents of jar file shows generated static files in the path (BOOT-INF/classes/static/index.html etc.)
I am new to AngularJS. In my project all views html are inside WEB-INF folder, I want to use AngularJS so I have written app.js and controller.js but view is not rendering.
How can I resolve this?
Don't put them in WEB-INF. By design, WEB-INF is inaccessible from the outside. You can put your templates anywhere you want, except WEB-INF.
Or, since you're apparently using Spring, configure it to serve those resources, instead of using the default servlet.
I'm trying to use Apache Tiles (version 3) in a spring project. As far as I can see, all tiles-files should be placed somewhere under WEB-INF directory. I'm not sure about this, this is just my observation: when I set war/WEB-INF/tiles/*.jsp it's ok, when I set war/tiles/*.jsp (and change my tiles-defs.xml to point new directory) I get
org.apache.tiles.request.render.CannotRenderException: ServletException including path '/tiles/basic.jsp'.
All tutorials I found on the web show that tiles directory is under WEB-INF\. Can someone make clear whether tiles directory have to be under WEB-INF (or maybe if other jsp files have to be there as well)?
No it doesn't have to be in WEB-INF, but it is actually the recommended way, moreover this is absolutely not Tiles specific, this is a general JSP/Java EE recommendation. (because of security reasons, the WEB-INF folder is not accessible directly)
E.g. here is a sample here where jsps our outside WEB-INF.