Setting up home page in spring - spring

I am new to spring environment. I have created small test spring project through STS.
Project name: SPTest
base package name: uk.co.ifTest
When I run and open this project browser through Eclipse. It work fine, but url, it put in the browser is xx.xx.xx.xx:8080/ifTest/, instead of //xx.xx.xx.xx:8080/SPTest/.
I guess, it is adding base package name.
Is there any way I can open project with http://xx.xx.xx.xx:8080/SPTest/.
Thanks
ish

You need to change your context path for the server to point from ifTest to SPTest.
This answer will help you identify how to do it:
Changing Tomcat context path of web project in Eclipse

Related

url after spring maven deployment

I have a basic question about deployment but I can't seem to find an answer on google...
I am working on a jakarta project and it's the first time I do the deployment.
Since I am using Spring-boot maven, I know there is an embedded tomcat that will launch with the jar.
My issue is, I don't know what url to use to check my project is working...
Before, I used the address http://localhost:9091/contextPath/endpoint, but now, I only get a whiteScreen...
So my question is, what url should I use ? Also, is there something else to do after packaging ?
Thank you for your answers.
EDIT:
Alright, so I tried actuator but that didn't help me...
With /actuator/mappings, I could see that my endpoints are correctly configured but when I use the executable jar, http://localhost:9091/contextPath/endpoint odes not work while it does if I compile with my IDE...
I don't know what url to connect to just to see the index... I'm using a very basic spring framework (boot and mvc) and my IDE is intellij community if this helps anyone
EDIT 2:
I tried to deploy the app on a local Tomcat9 to see if something would change but the connexion is reinitialized everytime I try to deploy a war using the manager, and there was no trace of error in the logs.
I tried using ./mvnw and it did work, endpoint and all, but it implies working with IDE environment
I tried using java (openjdk 13) and it compiled, but i couldn"t acces my own endpoint. I could still access the actuator endpoints so i don't know what to make of it.
Should the url be different depending on whether we are using IDE environment or just the jar?
EDIT 3:
Ok, I think have a lead but I have no idea how to resolve this:
when I began the web part of the application, I created a WEB-INF folder where I put all my jsp. My js and css files were in the resources/static folder. I tried once to put the jsp in the resources folder but it didn't work so I didn't push too hard.
Now, when I unzip the jar, i find my css and js files, but not my jsp.
When I unzip my war file, I have everything, but when I try to deploy it on a separate tomcat server, the connexion resets and I don't know why because nothing is written in the logs.
The issue then becomes:
Right now, I have
└──src
└──main
├──java
├──resources
| ├──static
| | ├──css
| | └──js
| └──template
└──webapp
└──WEB-INF
└──classes
└──jsp
What is the standard tree in intellij with jsp ?
By default Spring Boot apps are on port 8080.
Can you try http://localhost:8080?
Port can be changed in application.properties (or application.yml, application-profile.properties etc.) via server.port property (e.g. server.port=8888).
Ok, I managed to make it work.
I'm going to describe here everything of note that I encountered.
First, when I called my app to the usual url, there was no response (whiteLabel).
I added test logs and i found that I indeed called m controller.
I unzipped the jar and war i produced and came to the conclusion that the issue was architectural. I couldn't use jar, I had to use the war file.
I tried to deploy on a local tomcat server using the manager, but it always resetted the connection, so I took the manual approach - copy pasting the war file in the webapp directory.
Finally, the web pages were accessible in the browser.
Thank you for all the tips given during my research!
`http://endpoint:{PORT}/actuator/health` or `http://endpoint:{PORT}/actuator/status`
it should help but it must require spring-boot-actuator as a dependency in your pom/gradle file.

Can't create a spring starter project in spring tool suite

JSONException: A JSONObject text must begin with { at character 0
I used spring-tool-suite-3.9.1.RELEASE-e4.7.1a-win32-x86_64, why can't I create a project directly in File->New->Spring Starter Project
I got the screenshot below.
It may be late, but others might find it useful. I faced the same issue when I was trying to create a project in eclipse using Spring Starter Project.
What I did was change the Service Url from http://start.spring.io/ to https://start.spring.io/. I just changed the http to https and it worked. I don't know if it is a security related error or what, but I was able to create a project.
This is what I did:
In eclipse go to -> window -> preferences -> General -> Network Connections.
In Network Connections, select 'Direct' for Active Provider. And click Apply.
Now try creating spring starter project with - https://start.spring.io/ url.
Edit the URL to https://start.spring.io instead of http://start.spring.io (HTTP ⟶ HTTP/S).
This looks like a connection problem with start.spring.io (or a proxy in between your machine and start.spring.io) - or a temporary problem on start.spring.io.
If this problem persists, you can easily workaround it by using your browser, go to http://start.spring.io, select the boot modules you would like to use, and download a ZIP of the project. Then unpack it locally and import it using "Import -> Maven -> Import as Existing Maven Project" into STS.
Go to http://start.spring.io/ and generate the project there; pull
down the zip and extract into a folder (preferably with the top-most
dir being the same as the Artifact)
Import the project
That worked for me ....
Changing the URL from http://start.spring.io to https://start.spring.io
works for me .
In my case, I am in a corporate, and for that first you need to set up the proxy in the eclipse IDE; only then will it work.
just do the eclipse update .
in eclipse menu: Help>> Check for update , accept and install .
I had this same issue. Just connect to internet first and restart the STS.
The inbuilt wizard uses internet web service to work. See if this works for you!
Maybe it's too late but I solved it adding
-Djavax.net.ssl.trustStore=/home/[user]/.sdkman/candidates/java/11.0.6-zulu/lib/security/cacerts line to STS.ini. I hope you can solve it too

Spring 4, STS 3.7 tc server 3.1.1. how to enable insights for my existing web application?

I am new to Spring framework even though i have been a java dev for quite some time. I am impressed by the spring insight application demos in you tube and want to use it in my application. How ever, when i try to create a new tc server using the instructions provided, for windows 8.1 64 bit
tcruntime-instance.bat create --template bio --template insight -i C:\workspaces\eclipses\sts\sts-bundle\pivotal-tc-server-developer-3.1.1.RELEASE\insight-instance http-insight-server-stsdeployed
When i try to add the folder created as the location of the new tc server with insight configured, using STS-> server view-> right click-> new-> server-> selected v3.0-3.1- && server-runtime env->add->browse="newly created server instance directory" it shows me below error.
The Tomcat installation directory is not valid. It is missing expected file or folder tcruntime-ctl.sh.
any idea how to add a new server and run my application on it? or add spring insights to existing spring boot or spring web application thru maven or spring configuration?
Note: Even though im using STS, i would like to know how to use these instances with Eclipse or IntelliJ idea. Im on a windows 8.1 64 bit machine.
When you click "add" from your instructions, you are browsing to a new tc Server installation directory (the binaries you want to run) not the instance directory. Once you select the installation directory of the version you wish to use, you will select next in the configuration and it will give you the option to "Create instance" or use an existing instance. You will then select use an existing instance and point to your newly created instance directory.

How to run JAX-RS in Maven project of JAVA EE?

This is what I did on NetBeans.
New Project -> Maven -> Web Application
and gave my project name
And, created new RESTFUL Web services from patterns
selected Simple Root Resource
Assigned path "foo"
and hit finish
And now, I tried to access it from browser as
localhost:8084/context/webresources/foo
And, it shows 404 resources not found error.
I checked if it works with non-maven based projects, and it does. Accessing the resource was possible on those but, not on maven based.
I must have missed something.
I also tried to see if it is accessible from netbeans by doing right-click on the RESTful Web Services and clicking TestResource Uri,
It shows error
Unable to open resource url.
the uri of the rest location
Make sure project has been deployed successfully and the server is running.
While both have been done!!

Eclipse Java EE project and Spring : classnotfoundexception

I am trying to build an project in Eclipse (actually I'm using RAD, so basically eclipse, and when I say 'Java EE Project' I mean an 'Enterprise Application Project').
My Enterprise Application Project (the 'EAR' project) has two module projects :
- service
- web
The service project has some stuff in it, all wired up using Spring.
The web project has its own stuff in it, all wired up using Spring. The UI stuff in the web project needs to use the stuff in the service project.
Both projects are included in the EAR project as modules.
The web project lists the 'service' project as a dependent project in the build path, it's checked off for export, and also has it listed as a EE Module Dependency.
I'm having a really hard time to get this working though:
The spring context in the web project is of course what gets loaded when the application is deployed, and it imports the spring config I need from the service project. This seems to be working fine.
When spring tries to instantiate a bean it throws a ClassNotFoundException. On the very first bean.
I tried simply copying the spring config from my service context and pasting it into my web context, but I got the same ClassNotFoundException.
I have tried instantiating an object of that type (the class that spring says cannot be found) in the java controller class in the web project, and it is successful, both at compile time (no compile errors) and at runtime (no exceptions).
So the classes from my service project are not available on the classpath when spring tries to use them.
Any ideas what's going on here and/or what I might be able to do about it?
There is a class loader policy that you should use ParentClass First . That will be managed either through Application.xml or through web.xml . You need to check your xml's then try.
It's a class loader issue.
Since you're using Spring, I'll assume that you don't have EJBs. If that's the case, why do you need an EAR? Deploy the whole thing as a web project, in a single WAR.
Put all your .class and Spring configuration .xml files in WEB-INF/classes. Load the configuration using org.springframework.web.context.ContextLoaderListener.
I seem to have fixed this - I'm not sure exactly what the problem was but there must have been a small typo in my spring config. I decided to just start fresh with a new spring config and when I started building the new one back up things were working fine. There must have been a problem with the old one.
Thanks for the suggestions though.
Unfortunately we're not always able to change project structure. We're working on structures other people have put in place.
I looked into the ParentClassFirst vs ParentClassLast setting - it seems on websphere the ParentClassFirst setting is the default if you don't specify anything, so I'm leaving it without specification to get that functionality.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/crun_classload.html

Resources