Custom tomcat context.xml for Spring App - spring

I have a Spring App, and I would like change the session cookie path. I know this can be done in the server's context.xml file, but I don't have permission to edit that file on my server. Is there another way to do this, maybe by adding another context.xml file somewhere?
Btw, I added a context.xml file to my project's META-INF folder, but it didn't work.

Bundle your context.xml with your war file.

Related

how to set profile-specific applicaiton.properties(spring boot) outside war(jboss)?

I have spring boot application that I am running in jboss(instead of tomcat).
I am using spring profile for loading environment specific application.properties.
Profile specific application{env}.properties is working fine when placed under "src/main/resources/" however, it is not working when placed externally.
I tried setting property in jboss standalone.xml but application fails to start in jboss.
<property name="spring.config.location" value="C:/Dev/config/rt" />
Please suggest how to load the environment specific application.properties files that are not placed inside the war file.
I was expecting spring to pick the profile specific file from the folder but looks like that's not the case.
It appears that spring.config.location needs to have the absolute file location instead of folder location. so, updated spring.config.location in standalone.xml and it worked :
<property name="spring.config.location" value="C:/Dev/config/rt/application-dev.properties" />
You can provide externalized configuration file using below command when you are initially starting the application,
java -jar <your-jar-name.jar> --spring.config.location=<path><external property>
example :
java -jar mySample.jar --spring.config.location=./application-external.properties
read more
Generally it was picked very easily when it's placed under the 'src/main/resources' folder. suppose you have to different files for profiles like - application-dev.properties and application-prod.properties, you need to set only the current working profile in the application.properties like
spring.profiles.active=dev
and it will be picked easily. If it's doesn't you need to create a workaround by creating a new bat or sh file like run.bat and run.sh in the bin folder of the jboss and pass the file location like
--spring.config.location=
The complete command to be added in the bat/sh file will be
java -jar appName.jar --spring.config.name=application-dev --spring.config.location=c:/Dev/application-dev.properties

Read Spring properties in React

I have a Spring/React webapp. In my application.properties file I defined spring.data.rest.base-path = /apiso when running the app locally, everything is accessible on localhost:8080/api. If I deploy this to my tomcat, the all the stuff goes to localhost:8080/warname/api.
I can easily define my warname in my properties file. And in React,
path: '/api/myStuff'
I can access my data.
Also I can change that to
path: '/warname/api/myStuff'
and everything will work. But to make things easier, it would be better to read the warname from my pom.xml so I wouldn't have to change every path in my .js. How to get that done?
If you have a directory named ROOT in your Tomcat directory, you have to remove it and change the name of your war to ROOT.war so that when Tomcat explodes the war it will be the main root project.

Tomcat context.xml from META-INF folder for context root configuration

I have an application which is being deployed in Tomcat 8. This application needs to be the context root.
To do this, I put a root.xml file in conf\Catalina\localhost folder and it worked.
Now, the problem is that when i debug through IntelliJ idea (Remote host) it is not being deployed as the root application.
Seems like the only way to fix this problem is to add context.xml file in META-INF folder and specify the configuration there.
Now, when I do this, context root configuration from context.xml file is not being picked up.
Any thoughts on this? Ultimately, I just need to debug the application through a remote server.

ClassNotFoundException on Tomcat Server

I am using this tutorial to set up Tomcat Server. After I have put the HelloServlet.java in classes and Web.xml in the WEB-INF folder and I'm giving the command
localhost:9999/hello/sayhello
On the browser. I'm always getting ClassNotFoundException. If anyone can tell me where am I going wrong.
I'm using JDK1.6.0_30, and Tomcat7 for my sample application.
You need to put the compiled HelloServlet.class file (not the .java file) in the WEB-INF/classes folder.
Compile HelloServlet.java and place the output class file HelloServlet.class into
<TOMCAT_HOME>\webapps\hello\WEB-INF\classes\HelloServlet.class
One thing you should check is that, the HelloServlet.class should be in a package. Looks like you have a long way to go with Servlet and JSP... I recommend Head First Servlet and JSP for your reference.
In your 'WEB-INF' of 'classes' folder place the .class files and if your using JDBC, jsp's just Copy the .jar executable files into 'lib' folder. and make sure that xml file should contain the proper information.
you should follow below Web Application Directory Structure
WEB-INF/ --
web.xml --xml file
classes/ ---classes folder here we keep .class files Myservlet.class
lib/ ---lib folder here we keep all .jar files. Myapp.jar
Welcome.html
Welcome.jsp

Do i need a context.xml file to deploy spring webapp to tomcat

I am new to Tomcat, so I apologize if this is a dumb question. I have created a spring mvc webapp that currently runs locally using the maven-jetty-plugin.
I can successfully create the WAR file. I would like to deploy the WAR file into a tomcat6 instance. However, I am not sure if I need to create a context.xml file for tomcat? And if I do, where would I place the file in my spring webapp? My current directory structure looks like this:
src
|
|-main
| |-java
|-resource
| |-META-INF
|-webapp
| |-WEB-INF
|-web.xml
The context.xml file is used to configure application specific instructions for your container (tomcat). For instance, you can define JNDI resources, loggers, valves, etc. See Context Container for more details.
By default, Tomcat will auto-generate a default context.xml for your war if you do not specify one yourself and store it within its own configuration files in /conf/[enginename]/[hostname]/[context-root].xml
If you want to include it as part of your war, you can place it in /META-INF/context.xml within your war.
No, you don't. The context.xml file is optional, and by no means required by Spring.
context.xml is used to configure Tomcat itself. The defaults are sensible, there's no need to override them unless you have a good reason.

Resources