Hibernate Tools Configuration not finding entities in library project - hibernate-tools

When I create a new Configuration in the "Hibernate Configuration" tab, the Session Factory node correctly shows the entities that are listed in the persistence.xml file of the main project, but fails to find all entities from a library project.
I'm using annotation configuration.

This is due to the way persistence.xml works.
You can add an external jar to persistence.xml using the <jar-file> element. The tricky bit is to make it work in Eclipse, where compiled classes are spread around different projects.
As suggested by this answer, you can do so with a relative "file:" url:
<persistence-unit name="myPersistenceUnit">
<jar-file>file:../../LibraryProject1/bin</jar-file>
<jar-file>file:../../LibraryProject2/bin</jar-file>
The "current folder" is the compiler output folder ("bin" in my case) i.e. the one containing META-INF if persistence.xml is located at /MainProject/src/main/resources/META-INF/persistence.xml

Related

Create Externalized Configuration in spring-boot along with profiles

I have a spring-boot application with annotations instead of context.xml.
In my src/main/resources folder I have: application-dev.properties and application-test.properties.
which work perfectly for different profiles (while running with VM option like -Dspring.profiles.active=dev)
Now I need to externalize this properties with file in /opt/software/Tomcat8/conf/app.properties
Some props override each other, some don't.
in Tomcat config context.xml I say:
<Environment name="app.properties"
value="file:///opt/software/Tomcat8/conf/app.properties"
type="java.lang.String" override="false"/>
How to use it via JNDI in my application configuring app with no XML but annotations in Spring-bot application class?
I need it to have priority to inner jar properties according to
Link to Spring-boot.doc
One solution I found was to have the vm argument -Dloader.path with the external path when executing the application. Please keep in mind if you're using a fat jar you may need to create the package in Zip model, otherwise it will not work.

Accessing properties file from another module context

I use maven. My web application contains two modules and each has it's own spring context. First is packed to jar, the second one to war. The second one uses first module's jar and calls it's methods.
I need to add property file, which will be used by first module (via spring context). The main issue is that I should be able to access/edit this property file after war deployment.
How can I provide such a property file, that will be used in first jar module and can be changed after war module deployment?
Thanks.
Sorry, don't see the problem, you need to describe that better. From what I understood this is the way to go:
place a.properties in src/main/resources in the JAR module
use a PropertyPlaceholderConfigurer to make the properties available in the Spring context
it'll be packed in root of the JAR
the JAR ends up in WEB-INF/lib of the WAR which again is "root of the classpath" so to speak
Update, 2013-06-09
(question was updated based on comments to initial answer above)
Essentially what you seem to be looking for (still not quite sure) is how to load properties from a properties file that is not packaged with your WAR/JAR.
In this case you can skip all of the above steps except 2.
Use a PropertyPlaceholderConfigurer and specify the location of the file as classpath*:a.properties (see below)
Place a.properties anywhere on the classpath outside the WAR file.
Warning! Of course you can now edit the properties independently from releasing the WAR file but since Spring initializes the beans on application start and since all beans are singletons by default changes to the properties file won't become effective until you restart the app.
XML example
<bean class="....PropertyPlaceholderConfigurer">
<property name="location" value="classpath*:a.properties" />

Normalizing Spring Resource for use with JUnit & war?

I'm probably thinking about this incorrectly, but here's what I'm up against:
I'm injecting Spring Resource objects into my app that give me the location of security certificates, for example:<property name="certificateResource" value="SomeCert.p12" /> where certificateResource is of type org.springframework.core.io.Resource
Running under JUnit the Resource is a classpath resource and everything is fine. When deployed as a war under Tomcat the the Resource is in a Servlet Context and requires WEB-INF/classes/ prepended to the certificate.
I've tried a number of Resource prefix and wildcard combinations but can't come-up with a single string that satisfies both contexts. So far the "solution" is to override the bean definition in src/test/resources/test-applicationContext.xml but that means maintaining the strings in two locations.
Any pointers to better solutions would be appreciated, thanks.
I have tried to make a small but descriptive application using spring-test and spring-webmvc and using resources referenced in xml configs while these xml's are reused by production and testing spring configurations. Here is what I recieved: github.com/isopov/spring-resource-test
The central is the referencing of the prodcution xml config from the testing config:
<import resource="file:src/main/webapp/WEB-INF/applicationContext.xml" />
it is also possible to not import one xml from the other, but give each test several configs:
#ContextConfiguration(locations = { "classpath:test-applicationContext.xml",
"file:src/main/webapp/WEB-INF/applicationContext.xml" })
the resource itself resides in src/main/resources (I assumed you are using Maven or something derived from the "Standard Directory Layout") so is always accessible with "classpath:hello.txt" from any spring config.
I tested this with maven build, as web-application and running UTs inside Eclipse.

Intellij ApplicationContext errors being incorrectly highlighted

1) cannot resolve directory javascript
2) attribute p:cache-manager-ref not allowed here
3) cannot resolve symbol datasource
All shown in red below :
1) because my app context is in src/main/resources and gets copied to WEB-INF, so I how can I reference resources, by moving appContext.xml to WEB-INF ?
2) Intellij can't use p namespce as it does not require xsd ? But I have declared the namespace correctly - it validates in netbeans.
3) Don't know
Btw, these do not effect the correct running of my app. It works, and no errors are displayed in eclipse or netbeans.
Here is my artfiact set-up, the javascript and images directory are within webapp:
In fact if I try t manually add the resource directories to deployment I am prompted with he message it is a duplicate:
1) You need to configure a web artifact for your module to let IDEA know about your application layout.
2) You need to declare p-namespace, like xmlns:p="http://www.springframework.org/schema/p"
3) It seems your library does not contain debugger information. I'd suggest to use type="javax.sql.DataSource" here.

aop.xml name and location?

Is there a way to specify the name of the aop.xml file with LTW? or define another name and location?
I have several software modules that I use and that all use META-INF/aop.xml with different settings.
I include these modules in a web application and then it all dependens how it's deployed/unpacked, which aop.xml file is used ..
So I discovered after long time of searching that not all LTW weaving toke place correcting as it depends with aop.xml was used ...
Basically I need to use both aop.xml files, kinda of merging both contents of the aop.xml files...
How to do this?
Ed
When using AspectJ you can use the system property org.aspectj.weaver.loadtime.configuration to point to another config file. For example:
-Dorg.aspectj.weaver.loadtime.configuration=file:META-INF/myaop.xml
Duplicate of Load time weaving in AspectJ using aop.xml.
Furthermore, the AspectJ documentation says:
When several configuration files are visible from a given weaving
class loader their contents are conceptually merged.

Resources