How to set web.xml to org.apache.tomee.embedded.Configuration - web.xml

The essence of the problem: how to transfer your own web.xml file to
new org.apache.tomee.embedded.Configuration().setWebXml("file_name").
When I set http port as new org.apache.tomee.embedded.Configuration().setHttpPort(_port) works fine.
But, when set web.xml it does not work.

I think setWebXml is a dead config but you can setConf("/folder/in/resources") and put a web.xml in this folder. It will put it in conf folder and do what you want

Related

how can i set was: SpringBoot(tomcat) + web: nginx(bring the thymeleaf resource files from was) on docker in linux

It was a project with a base of springboot + thymeleaf.
I want to use the web server by using nginx to place the resource files of thymeleaf on the web server.
Running nginx and spring boot project (WAS) with docker container.
nginx uses a port number of 8003:80 and WAS 8002:8080.
At this time, I want to know the settings of nginx.conf and the settings of the application.yml file of WAS.
In the linux environment, there is a situation where mapping is not working properly depending on whether or not thymeleaf is "/", so I want to solve this.
The settings for nginx.conf are as follows.
server {
listen 80;
location / {
proxy_pass http://ipaddr:8002;
...
}
location /templates {
root /usr/resources/templates;
}
location /css/ {
alias /usr/resources/static;
}
}
The application.yml setting for WAS is as follows.
thymeleaf:
prefix: /usr/resources/templates/
suffix: .html
Some are omitted, but by default, they refer to the directory in the same way as above.
When you run each server, the was server and nginx seem to be calling normally, but they don't seem to map the screen that will eventually be displayed properly.
[TemplatesInputException: Error resolving template [common/pagename], template might not exist or might not be accessible by any of the configured Template Resolves]
An error is occurring. Please Help me.
I tried to modify the nginx.conf file in nginx and the application.yml file in was server in many ways.

Loading multiple config file from spring cloud config server

Hey I got to know how to check properties in config server i.e. http://{Config server URL}:{Port}/{ServiceID}/{Profile}
Right now I am facing a problem where I've to read multiple properties file from cloud config server. Ex: Right now I've to read properties file(huge file) from a single property file i.e. employee.properties
I don't want huge list of properties file in single folder. like
employee-dev.properties
employee-dit.properties
employee-sit.properties
employee-uat.properties
employee-preprod.properties
employee-prod.properties
customers-dev.properties
customers-dit.properties
customers-sit.properties
customers-uat.properties
customers-preprod.properties
customers-prod.properties
.
.
.
and soo on.
My requirement is I need to maitain a list of properties file and config server will provide me these values. like :
**{env}/employee.properties**
**{env}/customers.properties**
Here env could be any environment like dit, sit, prod etc.
Hope I'll get answer here.
If you don't want to have all properties files in an only folder, so you need to add this configuration on config server properties file.
1. Match all options
spring.cloud.config.server.native.searchLocations = [classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]
2. Match only /application-name/application-name-profile.properties
spring.cloud.config.server.native.searchLocations = classpath:config/{application}
Then you'll have matched based on application name folder for example.
resources/config/application-name/application-name-properties.

How do I load ${catalina.home}/conf/application.properties in a Spring / Tomcat webapp?

How do I load ${catalina.home}/conf/application.properties in a Spring / Tomcat webapp?
Looking around on StackOverflow and Google I see many discussions which claim it's possible. However, it's just not working for me. In line with the advice from my research my Spring applicationContext.xml file contains the following line:
<context:property-placeholder location="${catalina.home}/conf/application.properties"/>
But I get this in the logs:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties]
From the log entry I can see that ${catalina.home} is expanding correctly. When I expand it by hand in the applicationContext.xml file it returns the same error. The following returns the contents of the application.properties file as expected:
cat /Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties
So the path is clearly correct. Is this a webapp security or Tomcat server configuration issue?
The location of a context:property-placeholder is a Resource, which means that if you provide just a file path (as opposed to a full URL with a protocol) then the path will be resolved against the base directory of the webapp - it is trying to load /Users/username/Servers/apache-tomcat-6.0.36/webapps/<appname>/Users/username/Servers/apache-tomcat-6.0.36/conf/application.properties, which does not exist. If you prefix it with file: it'll work as you require:
<context:property-placeholder location="file:${catalina.home}/conf/application.properties"/>
For annotation based configuration you can use:
#PropertySource("file:${catalina.home}/conf/application.properties")

fsresource - runmode config stored in crx via xml

i'm using the fsresource sling extension to access the filesystem when working on JSP, JS, CSS and so on. When just yanking the bundle into the crx and configuring it via the OSGi console, everything works as expected. But when i try to add a new runmode (configurtion), the result is unsatisfying.
config/src/main/content/jcr_root/apps/samples/config/org.apache.sling.fsprovider.internal.FsResourceProvider.factory.config.xml
Is the path of the main configuration, which i'm using on a local instance to figure out, how to achieve the desired results, but the best i could get was an unbound configuration displayed in the
system/console/configMgr
The contents of the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
provider.roots="/apps/ui-samples"
provider.file="/Volumes/samples/ui/src/main/content/jcr_root/apps/ui-samples"
provider.checkinterval="1000"/>
Apparently, the i just thought too complicated about the name of the file.
org.apache.sling.fsprovider.internal.FsResourceProvider-samples.xml
for instance does the job.

Spring MVC and Log4j

I'm trying to get started Log4j in Spring MVC application, but I'm unable to get information, what's wrong. Each blog post is same: It's really easy. Just put log4j.properties into /WEB-INF/classes directory. But for me it does not work. The problem is, that there is no place to look for error message. The only I know is, that expected log file was not created. Is there some possibility to debug it? Really to put log4j.properties file in /WEB-INF/classes is enought?
The above mentioned log4j.properties file follows:
#Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\workspace-trainee-actual\\0pokusy\\Sprung\\logik.txt
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=trace, file
Controller using Log4j:
#Controller
public class HelloWorldController {
private Logger log = Logger.getRootLogger();
#RequestMapping("/")
public ModelAndView base() {
log.debug("base URI");
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
}
The only sure fact is, that it work's, so log is not null and the Log4j library is available.
Try adding
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
to your web.xml file
I have changed logging threshold of Geronimo to debug and I found '2011-06-24 07:33:18,353 DEBUG [root] base URI'. I thing there is some conflict. The application is one process, one JVM instance with thousands of classes, but with only one root logger for all of them.
Seams that you are right:
From the Geronimo Documentation:
Note that in any case, unless you use hidden-classes or inverse-classloading to load your own copy of log4j separate from the geronimo copy, log4j will not automatically read any log4j.properties files you may have included in your classpath.
I found the last "solution" from the documentation very interesting:
Copy the log4j.properties file by hand to the appropriate location such as var/my-app/log4j.properties. There is no need to include this file in your app.
Because that allows you to externalize the log4j configuration. So the Operations-Guy can manage and change the log4j configuration. And you do not need to build/and deploy a new version if for example the directory where the files are stored is changed.
Workaround
The system works properly allways. The Log4j system is configured for our instance of the Java Virtual Machine. Geronimo has already done it. We can not reconfigure the root logger, but we can use it. The default threshold is INFO and application uses root logger for a debug message. Thus we cannot see it anywhere.
If threshold has decreased to DEBUG, the message appears in Geronimo log. I have changed in the file $GERONIMO_HOME/var/log/server-log4j.properties a line at the beginning: log4j.rootLogger=DEBUG, CONSOLE, FILE And in $GERONIMO_HOME/var/log/geronimo.log I can then read: 2011-06-24 20:02:21,375 DEBUG [root] base URI
From some unknown reason is neither under Linux nor under Windows created separated output file. We can the message find just in server log, but it does not matter, we can overcome it. Let rename the logger in Log4j configuration: #Root logger for application
log4j.logger.springTestLogger=TRACE, APLOK
And in the code accordingly: private Logger log = Logger.getLogger("springTestLogger");
We create the separete log file under Linux easily: cat $GERONIMO_HOME/var/log/geronimo.log|grep springTestLogger > separe.log
Try with
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/properties/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Resources