I'm having a stupid configuration issue with Ibatis in my Spring project. Please don't jump on me about how all this was setup, I'm just following the "in house project structure policy".
So here is the structure, we have the "src/main/resources/META-INF/" folder that contains all of our config files used by the application, and then there is a "src/test/resources/META-INF/" that contains only the config files that have different settings to run unit testing.
Well in our case that's only one file, the src/main/resources/META-INF/spring/application-config.xml became the src/test/resources/META-INF/spring/test-application-config.xml. I'm am not going to outline the small differences between the two, because that part works fine.
The test-application-config.xml imports the src/main/resources/META-INF/spring/data-access-config.xml file just fine, which in turns use the src/main/resources/META-INF/ibatis/sqlmap-config.xml successfully... After that is when it goes to Hell.
See up until now we're using Spring to find the next config files in the classpath, but when we hit sqlmap-config.xml we leave the spring framework for the ibatis framework I believe, which loads the resource files defined inside it relative to the classpath (that's taken from the doc, whatever that means).
Inside the sqlmap-config.xml are defined a few resource files we're using that live inside the src/main/resources/META-INF/ibatis/mapping folder.
They are referenced like this:
<sqlMapConfig><sqlMap resource="/META-INF/ibatis/mapping/MyObject.xml"/></sqlMapConfig>
That works fine when I run the app normally, but when I run my JUnit test cases I get an IO exception stating that it can't find the file /META-INF/ibatis/mapping/MyObject.xml.
I've tried to change the path in the sqlmap-config.xml to "mapping/MyObject.xml" but that didn't help. I've also tried to use the Spring classpath prefix "classpath:META-INF/ibatis/mapping/MyObject.xml", didn't work either.
Anyone would have any idea on how to set that Ibatis properly so it works for both the app and the junit?
Thanks.
To solve this problem, I removed all the the Ibatis files and folders from the src/test/resources/META-INF folder.
The sqlmap-config.xml in src/main/resources/META-INF/ibatis/mapping file now maps like this:
<sqlMapConfig><sqlMap resource="META-INF/ibatis/mapping/MyObject.xml"/></sqlMapConfig>
Please note that compared to my initial post the leading "/" is gone... I think that's what made the difference here.
Hopes this helps anyone running into similar issues.
Just to see whether what you are saying is actually the problem.. you might want to place your mappings (MyObject.xml) in the same folder as sqlmap-config.xml. I say this because I've had my fair share of spring + ibatis + unit testing problems. (see resolved question asked by me)
Also, you might be getting IO exception because the mappings file does not exist outside the container (when you run tests).
You should also post definition for bean created from SqlMapClientFactoryBean. This should have configLocation property that contains path to sqlMapConfig xml
I had the same problem and could not find a (quick) solution that explained what exactly could be going wrong. Hence my answer.
As Spring documentation for Ibatis says:
Remember that iBATIS loads resources from the class path, so be sure
to add the 'Account.xml' file to the class path.
In your case by adding META-INF to your webproject build path i.e. if you used Eclipse, set <classpathentry kind="src" path="META-INF"/> in your projects' .classpath (This will be visible under Navigator view in Eclipse)
Related
Setup:
Intellij IDE community
Spring Boot 2.4.0
Spring rest docs
Hi,
I use spring rest docs in all my services. The problem is that in one of them, the custom snippets are ignored and I just don't know why. Although if i'm sure that it's a mistake of mine I just can't find it.
Example snippet
One of the snippets I want to customize is the http request.
So I placed a file http-request.snippet under src/test/resources/org/springframework/restdocs/templates/asciidoctor
Content:
[source,http,options="nowrap"]
----
{{method}} {{path}} HTTP/1.1
----
So I would expect that the requestbody is not documented in this snippet but instead it is still included.
Like I said all my snippets are ignored.
UPDATE:
I've debugged StandardTemplateResourceResolver class. In fact, my templates are ignored.
I looked at the path and as you can see the method getFormatSpecificCustomTemplate should resolve my snippets but it doesn't.
Is there something else I have to configure when I add a new resource folder and I add it to the classpath?
SOLVED
I found the problem by looking at the asciidoc path in my explorer. The problem was that the creation of the direktories went wrong. Instead of creatin nested subdirectories for org/springframework/.. there was one folder with the whole directory structure as one name. Sorry for the confusion but in intellij the structure looked right.
I'm working on a SpringBoot (2) application. I'm looking at our properties files which have become a bit convoluted and I'd like to tidy it a little.
In deployment we have a small main/resources/application.properties file which contains a few defaults and an external property file which contains a lot of other properties. This works well... and I'm trying to replicate this in dev and failing and I'm hoping I'm doing something silly which someone can point out painlessly.
As I understand it by default, Spring Boot will look in various places for the properties, in this order...
classpath root
/config in classpath
in the current directory
/config subdirectory of the current directory
Using Intellij I can't get SpringBoot to pick up 2 locations though. If I put all properties in main\resources\application.properties then that's fine. If I use -Dspring.config.name=dev and add a dev.properties with all properties this works well but I can't seem to configure a split in debug between defaults in main\resources\application.properties and a simulation of the external file somewhere else in the project (so that it won't get packaged in the jar).
Is there a simple way to do this, or any good documentation somewhere that I've missed that would explain it well enough that I might be able to simulate it in the dev environment ?
Currently, I'm working on a project which has a large number of dependencies.
During development, I sometimes have issue with some spring bean.
Normally, the stack trace can tell me the name of the bean. However, it does not shows me which context.xml file declares the bean. Moreover, it does not tell me which .jar file contains the context file and how that context file is imported into my project (I means the chain of import).
As there are many depedencies, not all context file are uses, many beans are override....
It takes me a lot of time to search the correct context file. One simple solution is to import all related project into my eclipse workspace and everything becomes horribly slow.
I'm thinking about writing a tools to speed up the process:
Given a name of spring bean / the class of bean, the tool will search in the whole class path of application and returns:
The spring context file which declares the bean.
The .jar file that contains the spring context file.
Extract the content spring context file and show it directly to user
If user provides the root spring context file, the tool will shows the import chain to the destination spring context file.
It does not take lots of time to implement this but I just wonder whether somebody has already implement it? I just don't want to reinvent the wheel.
I found the project https://github.com/julior/spring-inspector. It's interesting, but it's not what I need.
If you know a tool like the one above, I'd be very happy to know about it.
You totally should look at Intellij IDEA's great support for Spring Framework.
More information available here: http://www.jetbrains.com/idea/features/spring_framework.html
To find interesting bean in xml config you just need to click on green bean image.
Intellij IDEA is definitely worth its price.
I have an application with a Database module which contains the persistence.xml file along with entities and controller classes. During Maven tests it passed all tests so I believe it is well configured. When running the application it complains that it can't find the persistence unit. I verified that it is in the respective nbm's META-INF folder in the application folder being ran.
Any idea? Anything special to make it work?
Edit:
Code can be found here in the Marauroa-Server-Manager folder.
I was lead to the answer by Timon Veenstra. This is a placeholder for the answer in case Timon doesn't have an account so I can credit him with the answer and for anyone else running accros this question.
The key was making sure that the Persistence API, Persistence Implementation (Eclipselink on my case) and the database driver were wrapped in NetBeans modules. After that everything started working.
I guess Maven/NetBeans is misleading on that aspect since the modules compile if you have appropriate dependencies.
Might be a stupid question, but in my current maven project i do not have a web.xml in my /web-app/WEB-INF folder.
There is no web-xml in my project and never has been, im trying to add it but my application is non-responsive to anything written in the web.xml. What am i missing?, iv tried specifying the path to it through the config.groovy like:
grails.project.web.xml="web-app/WEB-INF/web.xml"
Am i missing something? Do i need to specify the web.xml in some other config file in order to make my project utilize it ?
Run
grails install-templates
to copy templates that Grails uses for all code generation activities (including "web.xml").
"web.xml" file will be created in "src/templates/war" directory.
You may be able to get away with something similar to this https://stackoverflow.com/a/5891646/107847. It doesn't install separate web.xml but does allow you add what ever content you need or edit any of the generated content.