How to modify Spring Template Project - java

i created the basic Spring +Jdbc seeing the following Spring + JDBC example
For this i used the Spring Template Project
i added all the classes inside src/main/java/
But now as i run the project by rightclicking the App.java Class ->run as->run on server.
it gives me the following error.
Requested Resource is not found.
url above is /app/WEB-INF/classes/com/shr/common/App.java
Now do i need to add the classes to WEB-INF/classes folder?
how should i run my project. please help me.

That is not a web application. You have to start it as Java Application (run as -> Java Application)

Related

PropertiesLauncher command line arguments not working with Spring Boot executable Jar

So I have basic multi-module Spring Boot project. The goal, that I had was to build executable jar and pass additional properties with the help of -Dloader.path=....
For some reason (if I understand purpose of this argument) loader.path is being ignored completely.
My project structure is following:
\-
|--conf
|---default
|--pets-api
|--pets-app (this module contains the Main-Class)
|--pets-domain
|--pets-infrastructure
Since no custom active profile is being passed it uses "default". Jar contains application-default.propeties file, that has single configuration server.servlet.context-path=/v1.
/conf/default location has 2 properties files:
application.properties
random.properties - this is bind to #ConfigurationProperties(prefix = "...") inside application
When I run it normally everything is fine java -jar pets-app-0.0.1-SNAPSHOT.jar. It just uses application-default.properties file and that is it.
Now when I am trying to utilize -Dloader.path argument as in java -Dloader.path=PATH/TO/conf/default -jar pets-app-0.0.1-SNAPSHOT.jar it starts application same as before, as if I am not adding 2 more file to classpath.
What is used:
Java 17
Spring Boot 2.6.12
Gradle
Did anyone come across this as well? Any suggestion on how to resolve it?
PS. If there is need to see the code, I can upload it to GitHub.

Configuring Spring Boot project with multiple Maven modules

I have a web project with following structure:
app
pom.xml
–modules:
app-api (contains only OpenAPI documentation used to generate REST endpoints)
pom.xml
app-service (contains the actual business logic with services/controllers/etc)
pom.xml
I am trying to manually run SonarCloud.
I put the following settings in the parent pom.xml
<sonar.organization>company-account</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.projectKey>project-name</sonar.projectKey>
All of the above are taken according to what the Sonar web portal is recommending.
I added the SONAR_TOKEN variable as well.
At the moment I am getting:
"Project ‘…’ can’t have 2 modules with the following key: …
I tried a bunch of other combinations, like putting the maven properties in the service submodule.
It either does not recognize the project or gives me a stackoverflow error.
I tried passing the project key as a parameter:
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=the-project-key
It just gives another error:
Project not found. Please check the ‘sonar.projectKey’ and ‘sonar.organization’ properties, the ‘SONAR_TOKEN’ environment variable, or contact the project administrator
Do you have any idea what am I doing wrong?

Want to change the context path in Spring boot application in an external Tomact server version 9

I want to deploy a Spring boot application in an external Tomcat server version 9. I am able to deploy it and working the endpoints also. But properties I have set in application.properties file those are not working. Like server.servlet.context-path=/myapp is is not working instead the context path which I am getting is http://localhost:8080/myapp-0.0.1-SNAPSHOT/api/ping.
I am using 2.3.10.RELEASE and Java 1.8 and Tomcat version 9.0.46 Can anyone please help me out with this.
But everything is perfectly working on embedded tomcat. Thanks in advance and any suggestion, comment is highly appreciated.
Can anyone please help me with how I can do this - My war file name would be myapp-0.1.war but the context path of the application would be like this localhost:8080/myapp/api/ping
Use finalName property in your build file (pom.xml for maven)
<finalName>myapp</finalName>
When you run a Spring Boot application in an external servlet container, the server.* properties do not apply.
If you are willing to change the naming convention you can drop a WAR file named myapp##0.1.war in the $CATALINA_BASE/webapps directory and benefit from parallel deployment (cf. parallel deployment).
If you want to stick to your naming convention, you can create a folder for your WAR files (e.g. $CATALINA_BASE/webapps-available) and create a deployment descriptor $CATALINA_BASE/conf/<engine_name>/<host_name>/<context_path>.xml (in your case probably $CATALINA_BASE/conf/Catalina/localhost/myapp.xml) with the following content:
<Context docBase="${catalina.base}/webapps-available/myapp-0.1.war" />

Java MVC project in Spring Tool Suite additional files

I'm learning to make Java MVC project using Spring Tool Suite tool.
The path to make new project is:
File->New->SpringLegacyProject->Spring MVC Project.
My question is: which directory I have to use to add additional not-Spring files and where and what do I have to type for Spring files to see them?
For example:
css files - where to put and how to make jsp views see them, will 'link rel="" 'tag be enough?
properties files used to specify database connection or to specify messages for ReloadableResourceBundleMessageSource. In this case, do I have to create bean for this class in root-context.xml?
Thanks.
You should probably use Spring Boot (i.e. use File->New->Spring Starter Project and select Web as a starter. Place your web resources under src/main/resources/static folder. They are picked up automatically from that folder.
You should try an example project: File -> New -> Import Spring Getting Started Content and then pick "Serving Web Content" from the list.
Try some DB getting started content example to get the answer for the second part of your question.

spring enabled web application

Hello gud fellas in my quest of learning spring, i created a web application with netbeans 6.7 in windows xp sp2.i've noticed some and have few question about that.
1 my applicationContext.xml config file is in WEB-INF and my test class cannot find it.i had a copy of it in source package under default package and i can be found.Isn't WEB-INF part of the classpath?
1.1 where should it normally reside in this case?
2 i've tried to use the SpringJUnit4ClassRunner class but couldn't find the library any where.how to add spring-test jar to my project in netbeans?
i've never tried it but i'ld like to know how to enable quartz in this project.From my understanding quartz comes with spring(correct me if i'm wrong).How to enable it
those are my worries for now.thanks for reading.
WEB-INF is not in the application classpath, no, but WEB-INF/classes is.

Categories