My project is implemented in Spring3 and configuration is almost xml.
Configuration of static resource mapping is like below:
<mvc:resources mapping="/a/**" location="file:/data/a/"/>
There is no problem when accessing /a/xxx.jpg but 404 Error is occurred when accessing subdirectory like /a/b/yyy.jpg. There is no problem about access authority of filesystem. How can I solve this problem? Additional configuration is needed?
(Add) Project directory is fine, but filesystem directory does not work
Use something like below :
<mvc:resources location="/" mapping="/resources/**"/>
You can specify classpath also to location any particular folder like below.
<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>
Related
I have the following servlet mapping present -
<mvc:resources mapping="/js/**" location="/resources/js/" />
Observation:
If any web request starts with the /js request path, then it will be mapped to the resources directory, and the /** symbol indicates the recursive look for any resource files underneath the base resource directory. Here I can access js/test.js, js/test2.js
Requirement :
I want to access only one specific file(js/test.js). How can I access specific one file(js/test.js) not all files which present into /resources/js location.
Can I use below servlet mapping :::
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
When you add this line
<mvc:resources mapping="/js/**" location="/resources/js/" />
Spring will add a filter rule which says
Whenever any URL with /js/** is fired, spring look for it recursively in /resources/js/ folder.
When you add following configuration
<mvc:resources mapping="/js/test.js" location="/resources/js/" />
Only URL with /js/test.js will be looked in /resources/js/ folder.
Please be mindful that any other request eg /js/jquery or js/abc will not be filtered.
I am new to Camel and I am using uri:validator in order to validate an XML against a .XSD file. However, I am not sure I am actually pointing to the .xsd file correctly as I my gradle build fails with the following error:
Caused by: java.io.FileNotFoundException: mydirectory\anotherDirectory\myxsdFile-v1.0.xsd (The system cannot find the path specified)
In my common-routes.xml file, I have the following:
<route>
<from uri="direct:util-xmltojson"/>
<log loggingLevel="INFO" message="XML Validation"/>
<doTry>
<to uri="validator:file:mydirectory\anotherDirectory\myxsdFile-v1.0.xsd"/>
<doCatch>
<exception>org.apache.camel.ValidationException</exception>
</doCatch>
</doTry>
</route>
Is this the correct way to use the validator component?
Thank you for your help,
I.
The validator component take in the uri the location of the xsd file used for the validation.
This can be:
A file, with validator:file:_path_. This path is relative to the folder of the execution of your application
A classpath resources (it's, in my opinion, the preferred way): com/test/package/resource.xsd : the schema will be looked in the jar, under com/test/package
A remote resource, with validator:http://remotehost/path : camel will download the resource in order to validate the xml
In your example, camel is looking for the file mydirectory\anotherDirectory\myxsdFile-v1.0.xsd which it doesn't found. Check if this file exist, relatively to the execution folder of your application. If this resource is static, you should place it in your jar, and use the classpath lookup.
I am trying to enable logging for cxf framework in weblogic application server along with log4j.
I have placed cxf.xml in domain home and have modified setdomainenv to add cxf.xml entry -Dcxf.config.file.url=cxf.xml.
I am setting System.setProperty("org.apache.cxf.Logger", "org.apache.cxf.common.logging.Log4jLogger") before making a webservice call and i have tried configuring all 3 types of configuration specified in http://cxf.apache.org/docs/configuration.html. But nothing seems to work.
I even tried creating org.apache.cxf.Logger file containing value org.apache.cxf.common.logging.Log4jLogger.
my log4j.properties
log4j.rootLogger = DEBUG, FILE
log4j.logger.org.apache.cxf=DEBUG
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=<>/logFile.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
CXF version: 2.7.5
Please suggest if there is change required for me to log both request and response xml?
Make sure your org.apache.cxf.Logger file is under META-INF/cxf. Inspect your war to make sure.
Also, assuming you are defining your services using jaxws, make sure you're defining loggers under the jaxws:inInterceptor and jaxws:outInterceptor
<jaxws:client id="..." serviceClass="..." address="..." >
<jaxws:outInterceptors>
<ref bean="logOut" />
</jaxws:outInterceptors>
<jaxws:inInterceptors>
<ref bean="logIn"/>
</jaxws:inInterceptors>
</jaxws:client>
<bean class='org.apache.cxf.interceptor.LoggingInInterceptor' id='logIn'/>
<bean class='org.apache.cxf.interceptor.LoggingOutInterceptor' id='logOut'/>
I am using spring web mvc project, and I put all the spring related files under WEB-INF\spring, including a ormlite.xml and a jdbc.properties.
Now I want to locate the jdbc.properties file in the ormlite.xml,Like this:
<context:property-placeholder location="/WEB-INF/spring/jdbc.properties"/>
But when I run the application ,it will told me that :
Could not load properties
It can not find the properties file.
What is the problem?
From Spring forum:
The problem is that /WEB-INF isn't accessible as it isn't in the root
of the path, you must use the same path as you use in your test case
(include the src/main/webapp part but that will break your application
from running).
I suggest you move the jdbc.properties to the src/main/resources
directory and simply use classpath: prefix to load the properties.
Code:
<context:property-placeholder location="classpath:jdbc.properties"/>
The code above assumes they are on the root of the classpath (which is
where they are when they are in src/main/resources).
I hope this can help someone else.
I had the same problem - property files outside the classpath.
My solution:
First define a properties bean:
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>/WEB-INF/your.properties</value>
</property>
</bean>
Then reference it in the property-placeholder:
<context:property-placeholder properties-ref="configProperties" />
Works perfectly well for me!
Instead of:
<context:property-placeholder location="/WEB-INF/spring/jdbc.properties"/>
Use:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/spring/jdbc.properties"/>
And your properties will be available in Spring file, and don't forget to add a namespace: xmlns:p="http://www.springframework.org/schema/p"
I think you're missing the prefix to instruct Spring how to attempt to load the properties. I think your definition needs to be:
<context:property-placeholder location="file:/WEB-INF/spring/jdbc.properties"/>
Note the addition of the file: prefix.
I am having problems when loading hibernate mappings from multiple paths.
My Spring session factory is define as follows:
<beans>
...
<bean id="sessionFactory" class="org.springframwork.orm.hibernate3.LocalSessionFactory">
</bean>
<property name="mappingLocations">
<list>
<value>classpath:/mapping/*.hbm.xml</value>
</list>
</property>
When I put my mappings Foo.hbm.xml and Bar.hbm.xml into the directory src/main/resources/mappings, then both mappings are found when Hibernate is initialized.
But when I put Foo.hbm.xml into the directory src/main/resources/mapping and Bar.hbm.xml into the directory src/test/resources/mapping, then only the latter mapping file can be found. Hibernate will fail with "cannot find mapping for Foo" error.
I can see that the mappings are copied to the directories target/classes/mapping and target/test-classes/mapping, so why cannot hibernate (or the spring local session factory bean) find both mapping files? I thought that "classpath:/mapping/*.hbm.xml" would find both target/classes/mapping and target/test-classes/mapping directories?
edit: I am getting this problem when running unit tests, so I expect that mappings found in both src/main/resources and src/test/resources would be found.
You are using maven. And since you put your Bar mapping into the test resource directory, it is only available when running tests.
I assume you have a persistence-unit configured similar to the example below
<persistence-unit ...>
<class>something.Foo</class>
<class>something.Bar</class>
</persistence-unit>
What happens at start-up is that Spring starts Hibernate, hibernates reads the persistence-unit and asks the factory for the mappings. But remember, Bar is only a test class. So Spring finds the mappings from src/main/resources, but since it does not run as a test, it does not see src/test/resources.