how to mock a repository with Mockito using data from xml file? I'd like to keep spring out of it if it's possible.
Related
I would like to generate Kotlin classes from a given wsdl file. How can I do this using a maven plugin like jaxb2-maven-plugin or cxf-codegen-plugin?
Thanks in advance!
Currently trying to get Micronaut to work with Pitest and it is failing due to an NPE caused by the fact Micronaut does not include the source file in the debug info of the outputted class.
I was wondering if there is a way to configure Micronaut to support this?
Reproducible sample of this issue
I was wondering if there is a way to configure Micronaut to support
this?
In currently existing versions of Micronaut, there isn't.
The classes in question don't have source files, not directly anyway. Annotation processors in Micronaut create classes to support other classes which live in the project which do have source files. It is conceivable that the annotation processors could reference the original source files in the generated .class files but offhand I am not sure what the implications of doing so would be. You are welcome to open an enhancement request at https://github.com/micronaut-projects/micronaut-core/issues.
How could I read properties form a separate file in Spring Boot ?
I'm trying what he's doing here.. http://www.mkyong.com/spring/spring-propertysources-example/
But it doesn't read the file?
say you have a file.properties in the resources folder.
you should put :
spring.configuration.location: classpath:file.properties
in application.properties to point to the file.
Then in your MyConfig class
#Service
public class MyConfig{
#Value("${prop.one}")
private String propOne;
Shouldn't this work? what am I doing wrong
Is there a simple example of doing this somewhere?
Thanks!
The simplest way to do this is to create an application.properties that will reside at the root of your jar
src
main
resources
application.properties
Spring boot will autoload this file as a properties file. This is a special feature of spring boot to look for the application.properties automatically. With regular Spring, you need to specify where the properties file is. They are demonstrating how to add a new properties file with regular spring.
For a separate properties file from the standard application.properties, you can add the #PropertySource annotation to your configuration class. This annotation will load the properties into the spring environment.
I have REST (Jersey) webservice that makes use of some data objects that are marshalled/unmarshalled to/from XML. The data objects are in a separate project/jar that the webservice war depends on.
I'm using MOXy as my JAXB implementation since I'm deploying to Glassfish and that's already included. I know I need a jaxb.properties file to set the JAXB implementation to MOXy with this entry:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
The question is, should the jaxb.properties file be included in the data object jar or in the webservice war or both?
If you don't want or can not use the jaxb.properties (you have a lot of package, the model is in a external jar, you want only java and no configuration files...), you can directly specify the JaxbContextFactory :
Do not create the context using :
JAXBContext jaxbContext = JAXBContext.newInstance(new Class[]{Person.class, ObjectFactory.class}, properties);
But instead, specify the factory to use :
JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]{Person.class, ObjectFactory.class}, properties);
where the factory is :
import org.eclipse.persistence.jaxb.JAXBContextFactory;
It is exactly the same, but it is specified explicitly in the java code instead of implicitly in a configuration file.
You package the jaxb.properties file with your model classes. GlassFish does not include the MOXy bundle yet, but you can add it easily. Check out my blog for more info:
http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-35.html
I'm happily using the Maven bundle-plugin to create OSGi manifest headers for my modules. However, when there are configuration files that pull in classes which aren't referenced directly in the code, the plugin can't tell which packages it's going to need.
One example is a bundle with domain models that constitute a Persistence Unit for JPA. The driver class is part of the PU configuration and either set in an XML file or at runtime when the EntityManager is instantiated. I have to manually add an Import-Package header for the driver class that I want to load, or I get CNF errors.
Another example is a Struts war, where the web.xml pulls in the Struts dispatcher that's otherwise not found anywhere in the code and has to be manually added to the headers.
How can I avoid this?
I tried adding the required packages as dependencies with a provided scope, but that didn't help.
In the plug-in section of the bnd configuration you can specify plug-ins to analyze these files and contribute to the import-package header. For spring it looks like this:
<_plugin>aQute.lib.spring.SpringComponent</_plugin>
I am not sure, what descriptors are supported on top of spring. Just take a look at the source (it's in the Apache Felix SVN) and see for yourself. In the worst case you have to write your own plug-in, but at least it is possible! Also peter kriens site about the bnd explains the usage and some internals.
Other then that I am not aware of any simple solution.