Tomcat 7: BeanInitializazionException with Spring MVC and external property file - spring-mvc

I have a web application bulit in Spring MVC that has an external property file.
The external file is defined in application-config.xml as follows:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- file di properties -->
<value>file:/myfolder/myfilename.properties</value>
<value>classpath:environment.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
The file is in /myfolder and is under my C:\ folder, but I need to deploy it (in production environment) on a Linux machine in which the property file path is /myfolder.
This web application runs well in Netbeans IDE (8.2) with local Tomcat 7 instance.
I am trying to run it in Eclipse with same local Tomcat 7 instance but I obtain the following exception:
ERROR ContextLoader:319 - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: \myfolder\myfilename.properties (Impossible to find the path specified)
I've tried to change the server configuration in Eclipse, but nothing happens. How can I solve this issue?

Related

Session replication not working in glassfish on multi node cluster

Session replication not working in glassfish on multi node cluster
1) application contains distributable tag in web.xml
2) application when deployed in cluster c1, which contains 2 instances present on same node, session replication works.
3) Same application when deployed in cluster c2, which contains 2 instances present on two CentOS machines, session replication does not works.
Following are content of glassfish-web.xml (if required for reference) :
<glassfish-web-app error-url="">
<session-config>
<session-manager persistence-type="replicated">
<manager-properties>
<property name="persistenceFrequency" value="web-method" />
<property name="relaxCacheVersionSemantics" value="true"/>
</manager-properties>
<store-properties>
<property name="persistenceScope" value="session" />
</store-properties>
</session-manager>
<!--<cookie-properties>
<property name="cookieDomain" value="node2"/>
<property name="cookieDomain" value="node4"/>
</cookie-properties> -->
<cache max-entries="4096" timeout-in-seconds="30" enabled="false">
<default-helper/>
</cache>
</session-config>
<context-root>/contextNaam</context-root>
<class-loader delegate="true"/>
<resource-ref>
<res-ref-name>jdbc/safe</res-ref-name>
<jndi-name>jdbc/safe</jndi-name>
</resource-ref>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
Edit : 1) Does not seems to be a UDP communication issue between 2 centos machines.
2) Tried to create tcp-cluster as mentioned in HA-administration-guide also, but still same effect, session not replicated on tcpcluster.
There was a bug in Shoal and incompatibility with Grizzly. I have fixed it in Payara and the fix is now in Glassfish too.
Current state is that it seems it works (Payara 4.1.1.154).
Under CentOS, you might run into trouble with SELinux and firewall rules. I suggest you disable them and try again.
I had a similar issue, though using JBoss, not Glassfish.
E.

Could not start GlassFish SERVERE: CORE10012 Application previously deployed is not at its original location any more

When i deleted the projects that i deployed once in the past,
i could not start the server because of this error:
Launching GlassFish on Felix platform
INFO: Running GlassFish Version: GlassFish Server Open Source Edition
3.1.2.2 (build 5)
INFO: Registered
org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for
persistence-type = replicated in BackingStoreFactoryRegistry
INFO: Grizzly Framework 1.9.50 started in: 125ms - bound to
[0.0.0.0:8181]
INFO: Grizzly Framework 1.9.50 started in: 109ms - bound to
[0.0.0.0:4848]
INFO: Grizzly Framework 1.9.50 started in: 31ms - bound to
[0.0.0.0:7676]
INFO: Grizzly Framework 1.9.50 started in: 125ms - bound to
[0.0.0.0:3700]
INFO: The Admin Console is already installed, but not yet loaded.
SEVERE: CORE10012: Application previously deployed is not at its
original location any more:
file:/C:/Documents%20and%20Settings/2796/My%20Documents/NetBeansProjects/mavenprojectJSF/target/mavenprojectJSF-1.0-SNAPSHOT/
SEVERE: CORE10012: Application previously deployed is not at its
original location any more:
file:/C:/Documents%20and%20Settings/2796/My%20Documents/NetBeansProjects/jsf1/build/web/
SEVERE: CORE10012: Application previously deployed is not at its
original location any more:
file:/C:/Documents%20and%20Settings/2796/My%20Documents/NetBeansProjects/struts/build/web/
SEVERE: CORE10012: Application previously deployed is not at its
original location any more:
file:/D:/self%20learning%202014/struts2/Struts2-ExecAndWait-Interceptor-Example/Struts2Example/target/Struts2Example/
INFO: GlassFish Server Open Source Edition 3.1.2.2 (5) startup time :
Felix (2,078ms), startup services(1,422ms), total(3,500ms)
SEVERE: Shutting down v3 due to startup exception : No free port
within range:
8080=com.sun.enterprise.v3.services.impl.monitor.MonitorableSelectorHandler#14fccd
INFO: Server shutdown initiated
INFO: Already stopped, so just returning
I modified the file
domain.xml
In
C:\Program Files\glassfish-3.1.2.2\glassfish\domains\domain1
And removed the application tags of xml and application-ref tags too for those projects mentioned above.
And i deleted the projects folder when i searched inside the glassfish folder
in
--> domains folder --> applications folder
To make it as i never deployed any personal project with it.
This way you are undeploying the applications on server without starting it that what was causing the error
I have encountered the same problem under Glassfish 4.1 after having migrated from Netbeans 8.2 to IntelliJ Idea.
To solve this problem I have only deleted application tags in domain.xml file.
I have deleted lines commented in following code
<applications>
<!-- TO-DELETE
<application context-root="/tlga" object-type="user" name="web" directory-deployed="true" location="file:/C:/GIT_SOURCES/TLGA-Web/web/target/tlga-1.18-SNAPSHOT/">
<property name="archiveType" value="war"></property>
<property name="appLocation" value="file:/C:/GIT_SOURCES/TLGA-Web/web/target/tlga-1.18-SNAPSHOT/"></property>
<property name="org.glassfish.ejb.container.application_unique_id" value="100406159636627456"></property>
<property name="org.glassfish.persistence.app_name_property" value="web"></property>
<property name="defaultAppName" value="tlga-1.18-SNAPSHOT"></property>
<module name="web">
<engine sniffer="ejb"></engine>
<engine sniffer="security"></engine>
<engine sniffer="webservices"></engine>
<engine sniffer="weld"></engine>
<engine sniffer="jpa"></engine>
<engine sniffer="web"></engine>
</module>
</application>
<application context-root="/tlga" object-type="user" directory-deployed="true" name="tlga-1.17.3" location="file:/C:/GIT_SOURCES/TLGA-WEB/web/target/tlga-1.17.3/">
<property name="archiveType" value="war"></property>
<property name="appLocation" value="file:/C:/GIT_SOURCES/TLGA-WEB/web/target/tlga-1.17.3/"></property>
<property name="org.glassfish.ejb.container.application_unique_id" value="100519021875888128"></property>
<property name="org.glassfish.persistence.app_name_property" value="tlga-1.17.3"></property>
<property name="defaultAppName" value="tlga-1.17.3"></property>
<module name="tlga-1.17.3">
<engine sniffer="ejb"></engine>
<engine sniffer="security"></engine>
<engine sniffer="webservices"></engine>
<engine sniffer="weld"></engine>
<engine sniffer="jpa"></engine>
<engine sniffer="web"></engine>
</module>
</application>
-->
</applications>
For me, DOMAIN.XML file is located in another location. To find it, I have searched to DOMAIN.XML files in c:\Glassfish.4.1\glassfish\domains folder.
I have deleted the 2 existing "/tlga" domains. Removing only one doesn't resolve my issue.
Explanation of how this error occurs:
These 2 <application> tags has been automatically generated by IntelliJ IDEA ULTIMATE 2018.2 !!! The first time I have deployed tlga-1.17.3, I don't have encountered any problem.
But this version was PRODUCTION version!
I have then switched GIT environment from PRODUCTION to DEVELOPMENT. I have build new release and started application again.
I suppose that IntelliJ has added a second <application> tag in domain.xml file and started again Glassfish that has refused to start !

Adding a directory to tomcat classpath and read the property file in spring

I am trying to read the test1.properties file which is located at an external folder.
here is my spring config file:
<bean id="propertyConfigurer3" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:test.properties</value>
<value>classpath:test1.properties</value>
</list>
</property>
</bean>
if I place the test1.properties in the tomcat7/lib folder, I am able to read it.
However, I want to place it in a different directory as tomcat7/env/test1.properties
I have added the path to the the conf/catalina.properties:
common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/env
This its not working, please help
solution:
Ok.. finally fixed it.. I had been doing it correctly this whole time.. it was my IDE which caused the problem.
The IDE was not picking up the changes in the catalina.properties file. I had to delete the server config in my IDE and re configure it.
these links were helpful in general:
Adding a directory to tomcat classpath
http://www.mulesoft.com/tomcat-classpath#solutions
Ok.. finally fixed it.. I had been doing it correctly this whole time.. it was my IDE which caused the problem. The IDE was not picking up the changes in the catalina.properties file. I had to delete the server config in my IDE and re configure it.
these links were helpful in general:
Adding a directory to tomcat classpath
http://www.mulesoft.com/tomcat-classpath#solutions
Use setenv.sh in the bin directory. If the file doesn't exist, create it.
To add something to the classpath use the following syntax:
CLASSPATH=/yourdir/
For windows: setenv.bat
Solution: creating the setenv.bat file under tomcat bin folder helped me in WINDOWS.
If your intention to keep file outside the war or ear , so that you can update it without compling and creating war again. just editing the file and restarting the server. Keep it in any external folder , even outside server and give absolute path in spring.
<bean id="propertyConfigurer3" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:test.properties</value>
<value>**file:/someexteranal/dir/test1.properties**</value>
</list>
</property>
Best thing , you can give this / path with root in Unix/linux and same will work in windows, just need to keep file in directory where your server is installed.
Like your tomcat in D drive , then keep it in D:\someexternal\dir and above code will work fine there too

Where does one place share beans in the extension path in alfresco?

I am trying to figure out where to place a share bean in the extension path. I have tried placing it in the following directories:
1) tomcat/shared/classes/
2) tomcat/shared/classes/alfresco/
3) tomcat/shared/classes/alfresco/web-extension
The bean has been declared in the custom-slingshot-application-context.xml along with some localized resources (the .properties files <== They get picked up). Some additional info. It's a share side bean because I can drop the package into the src directory of the expanded war file in the IDE and run share and it'll work.
Update
This is the custom-slingshot-application-context.xml content:
<beans>
<!-- Override WebScript Messages - add slingshot application messages -->
<bean id="webscripts.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>webscripts.messages.webscripts</value>
<value>alfresco.web-extension.messages.common</value>
<value>alfresco.web-extension.messages.slingshot</value>
<value>alfresco.web-extension.messages.profPerson</value>
</list>
</property>
</bean>
<bean id="webframework.factory.user.profPerson" class="com.test.ext.profUserFactory" parent="webframework.factory.base" />
</beans>
It seems you're using Tomcat, but as #Gagravarr mentions unless you are using the Tomcat supplied by the Alfresco installers, then the shared/classes directory is not enabled out of the box.
In Tomcat6/7, you need to add the following line to your conf/catalina.properties file (or modify it if it is already defined)
shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar
More information is available on the Install Tomcat6 wiki page.

External properties loader with Tomcat server

I am trying to deploy a spring mvc webapp into a tomcat server. I have been testing locally using the maven-jetty-plugin. In my spring configuration I am using a properties placeholder, and pulling my properties from an external file:
<context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="true"/>
<bean id="modelPropertyPlaceholder" class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="searchContextAttributes" value="true"/>
<property name="contextOverride" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:default.model.properties</value>
<value>file:/etc/app/app.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
This worked with my jetty plugin...however when I deploy the WAR file to the tomcat server I receive the following error:
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
In my external properties file I have the driver class and connect url defined. as so:
jndi.jpa.rms.datasource=jdbc/testDS
rms.db.driver=com.mysql.jdbc.Driver
rms.db.url=jdbc:mysql://testdatabaseurl:3306/test
rms.db.user=sa
rms.db.password=asfdas
rms.db.checkconnsql=select 1
rms.hibernate.generateddl=false
rms.hibernate.showsql=true
rms.hibernate.dbdialect=org.hibernate.dialect.MySQLDialect
Update:
It seems that tomcat does pickup the external properties file:
14:23:09.803 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'modelPropertyPlaceholder'
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from class path resource [default.model.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from URL [file:/etc/app/app.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/${config}]
14:23:09.811 [main] WARN o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
I'm not sure why tomcat isn't picking up the connection url and driver.
Is this a tomcat issue or am I missing something? Thanks
It's not a Tomcat issue, you must have made some minor mistake and properties are not loaded.
Are properties files located in proper place on your Tomcat environment?
Are you sure that in those properties files you have not left some keys blank?
If both answers to that questions are true, try changing your config with following:
<context:property-placeholder location="ADD_PATH_TO_YOUR_FILES SEPARATED_WITH_SPACES"/>
I guess that you are mixing here two property placeholders, one 'regular' and the other - bounded to servlet context. I can bet that somehow they get overlapped and one of them is getting silently ignored.
I would just stick to property-placeholder.
Old question, but...
Judging from the log output, it appears that Spring has not resolved your ${config} reference, or else this would have been substituted into the path given in the last log message:
Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
Here's a case I just encountered where it resolved ${catalina.home}/conf/myprops.properties correctly but was unable to load the referenced file:
Could not load properties from ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]: Could not open ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]
I tracked down the error in my case - I needed to prefix the external file reference with 'file:'. That is, it should have been file:${catalina.home}/conf/myprops.properties
(It is possible the Spring version difference may have impacted on the log output for you though also, and that it did resolve the reference but just did not show this in the output. For reference, I'm using Spring 4.1.6 at present).

Resources