Spring 3.2.0 release, Hibernate. Exception -
class path resource [hibernate.cfg.xml] cannot be resolved to URL
because it does not exist
File path - src/main/java/hibernate.cfg.xml
This destination and file template was autogenerated by Intellij IDEA. Google tell me, that one of solution - delete classpath prefix, but i have no file with this propety.
put it to src/main/resources instead
Related
Getting the following exception in intelliJ.
Caused by: class org.apache.ignite.IgniteException:
Spring XML configuration path is invalid: example-ignite.xml.
Note that this path should be either absolute or a relative local file system path, relative to META-INF in classpath or valid URL to IGNITE_HOME.
How can i fix it?
Thanks
If your configuration bean's definition has abstract=true parameter, try removing it if it does.
I think, the problem is that example-ignite.xml file has only abstract IgniteConfiguration. This is the case in the default configuration file in examples.
I had this problem. my issue was due existing error in config.xml file. for test, i ignore config.xml from environment variable (-v) and run ignite without it and after i saw that it worked, i figured out that issue is cause that.
i worked with ignite in docker in linux.
I had this problem and fixed with fake solution, , i used config file by internet path and not local file system path. i set config.xml on one domain path (https://example.net/config.xml) and then i set this path for spring xml configuration path.
I have created json file inside resources dir in spring boot application. File path is like: resources/recipe/recipe.json
When i use relative path, it won't be taken by java compiler so i'll get this exception.
java.io.FileNotFoundException: recipe/recipe.json (No such file or directory).
But this path is identified by IDE. if i click the path, it will be redirected to json file. Can anyone tell what the issue is ?
(FYI: absolute path is working perfectly)
If you have the resources folder in your classpath, then you should use Spring's Resource classes and specify the resource location as
classpath:recipe/recipe.json
You probably want to read this answer:
Spring Boot - Reading Text File using ResourceLoader
If your resouce is present inside resources/static/listing.csv
String path = "classpath:static/listings.csv";
ResultSet rs = new Csv().read(path, null, null);
If you need to access a file which is not in the classpath, you can provide the relative path from the root module directory.
E.g.
new File("src/main/resouces/recipe/recipe.json");
I have a Spring Configuration java file in my project (i.e. with #Configuration annotation). Now I'm creating a bean of SpringLiquibase in this class. The main file of changelogs i.e. db.changelog.xml file is in resources folder. So directly it's accessible from resources folder if I use springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); method. But when I try to access other xml files from db.changelog.xml file with <include file="src/main/config/db/db.changelog-main.xml" /> I get error that folder and file is not found.
Here, I want to keep db.changelog.xml file in resources folder and all other new changelog files in config folder which should be at same level as resources. The reason for this is, in resources folder, packages are there so folder structure config/1.0.0 is considered as config/1/0/0 which I don't want.
Is there any way to achieve this structure (shown below) with the current set up in my project?
config
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
resources
db.changelog.xml
or
config
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
db.changelog.xml
resources
I found the solution for this. Before this, I had copied the folder src/main/config into src/main/resouces in netbeans so it took that folder as package. So the folder name - config/db/1.0.0 got changed to config/db/1/0/0, but when I created new folder in resources folder, it worked and all the files in folder 1.0.0 are accessible correctly. Now, my folder structure is like this:
resources
config
db
1.0.0
db.changelog.201412120101.xml
1.1.0
2.0.0
db.changelog.xml
I can access db.changelog.xml file from my Spring class as,springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); and other changelog files from db.changelog.xml file as, <include file="classpath:config/db/1.0.0/db.changelog-201412120101.xml" relativeToChangelogFile="false" />.
Liquibase uses the application classpath, so as long as config is in your classpath you should be able to load them as well.
They would have a path relative to config, so something like "src="1.0.0/db.changelog.201312120101.xml" in your example.
If config isn't in the classpath, you can use the relativeToChangeLog="true" attribute with a src="../../config/1.0.0/db.changelog.201412120101.xml" but having config directly accessible by liquibase is the cleaner option.
I am wetting my hands in Spring and using Eclipse along with Spring. I have written a very simple Spring application with eclipse to inject a property in a bean. However, when I am running my application, Spring is throwing exception and it seems that the Spring is not able to find the Spring configuration file. Below is the stacktrace --
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
I have tried the following -- Give the full path in the ClassPathXmlApplicationContext method like --
ApplicationContext context = new ClassPathXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
I have also updated the ClassPath variable in windows to add the path for my spring configuration file. But nothing worked. Any idea would be highly appreciated.
Try this
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:Beans.xml");
And of course your Beans.xml must be in classpath.
Update or maybe
ApplicationContext context = new ClassPathXmlApplicationContext("file:src/main/Beans.xml");
Beans.xml should be in classpath. You cannot give full physical path of xml file for ClassPathXmlApplicationContext . Please check if Beans.xml is there in build path of eclipse.
As you are using a full filepath for your Beans.xml example, use
ApplicationContext context = new GenericXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
BUT it is not recommended to do this. Use the ClassPathXmlApplicationContext for this instead.
Then move Beans.xml into the classpath. The simplest way to do this is to move it to the root of your java source if not using Maven or src/main/resources if using Maven
If it's not much of a bother then try using Spring Tool Suite. It's a Spring friendly IDE based on Eclipse, so that you don't have to depend on spring/maven plugin configurations. All you have to do is go and create a Spring Project instead of Java project and rest all the settings will be handled for you.
If you are using Spring Tool Suite (STS), it may be the case that when you create a Maven project the src/main/resources directory was configured with "Excluded: .". In other words, STS sets your src/main/resources directory to have all its contents excluded from output by default.
How to fix it:
Project properties (Alt+Enter) -> Java Build Path -> Source
On src/main/resources, you may see "Excluded: ."
Select this item and click on Edit...
Remove the . exclusion pattern
Click OK. Voila!
I have a openJPA based project that I need to deploy it in format of aar into the following folder under Tomcat.
tomcat\webapps\axis2\WEB-INF\services
But it seems that the service cannot load the persistence.xml file in the META-INF folder within the aar file. I found a solution to rename the aar file into jar, like DummySerivce.aar -> DummySerivce.jar and then put the DummySerivce.jar into the lib folder, to be exactly
tomcat\webapps\axis2\WEB-INF\lib
This time, the persistence.xml could be loaded and the service worked well. But this unnecessarily imported a jar file which was not included in the specification.
So my question is, is there any way to load the persistence.xml from a aar file? is it possible to overload the path of persistence.xml file in code?
btw, only entity information are left in the persistence.xml, database connection parameters are already define in code, and I'm using Axis2.
Thanks!
I have found a solution.
By adding the following line into the services.xml, persistence.xml packed in aar file could be successfully loaded.
<parameter name="ServiceTCCL">composite</parameter>
for detailed info. please refer to http://wso2.org/node/1131
Now checking if there's any side effect.
TCCL - Thread context class loader
default - Status quo, normal behavior
composite - TCCL contains all
jars from environment (say webapp) and those specified in the
service
archive (aar) file under /lib service - TCCL contains all jars from
service archive (aar)