I'm using convention plugin in my project and everything was fine until I needed to add a custom interceptor.
To add a custom interceptor I need to have struts.xml in my project. But when I add struts.xml, it gives me 404 error for every page.
I have tried this solution but it doesn't seem to work.
The struts.xml configuration file should be in the source folder, such as src or resources. When you build the application the compiled output directed to WEB-INF/classes. You can check this file exists before you deploy or start a server with already deployed web application.
FYI, the convention plugin doesn't replace the XWork configuration, but extend it with possibility to override. The struts.xml is used by the same purpose, but using different configuration provider.
So, configuring interceptors using convention plugin make sure you use the right parent package that contains your custom interceptor.
Related
When I use Spring and want to write a unit test, I can specify a custom context configuration in various ways, for example, by providing a different path of the context.xml.
But I don't see the way how to do that for CDI if I want to use a custom dependencies configuration for testing in the same maven module.
The documentation is very strict about this point:
For EJB modules or JAR files, the beans.xml deployment descriptor, if
present, must be in the META-INF directory.
If there is already /META-INF/beans.xml in the sources, I can not place a different one into the test-resources (it simply will be ignored).
Is any way to configure Weld/CDI, may be by using some system variables, to change the path of the beans.xml?
For EJB modules or JAR files, the beans.xml deployment descriptor, if present, must be in the META-INF directory.
That is true, however that concerns an already created/packaged JAR which you then use as a dependency of your app. But your app can have it's own beans.xml too. beans.xml is just a means to define one bean archive and certain structures (interceptors, decorators, ...) within that archive. That means, for instance, that an interceptor enabled via beans.xml inside that JAR library will not be enabled in your application unless you specify it in beans.xml of that app too. Hence the link you see between the documentation and the testing you are asking about might not be correct/relevant. Not sure if I got you right there, though.
Is any way to configure Weld, may be through using some system variables, to change the path of the beans.xml?
No, there isn't. But in EE you mostly test with Arquillian and that allows you (among other things) to define a test deployment. There you can include any custom beans.xml you desire. That's also what Weld/CDI TCK tests use most of the time.
My application has two separate maven projects.The first project is core project which has dao and bean classes. The second project is web project which is having spring rest classes. This web project has web.xml and spring-servlet.xml files. The core project has spring.xml file which has jdbctemplate and other bean definition codes like and datasource information.
I have written this code in spring-servlet.xml of web project to import the spring.xml file of core project.
<beans:import resource="classpath:/mycarecore/src/main/resources/spring.xml"/>
Now, when I am building the war file, the war builds fine but when I deploy the war on server and starts the server, it gives file not found exception for spring.xml file. I have given the project reference in maven dependency and I can see the jar of core project inside the war generated war. I have done multiple changes in file path, but it didn't help. Because of this, I am also not able to use jdbctemplate in my dao layer.
Please help.
The url for the classpath seems like an absolute url. This will work only if the spring.xml is located at /mycarecore/src/main/resources/spring.xml path on your computer. Otherwise you should simply use: classpath:mycarecore/src/main/resources/spring.xml.
From Spring documentation:
"You can always use fully qualified resource locations instead of relative paths: for example, "file:C:/config/services.xml" or "classpath:/config/services.xml". However, be aware that you are coupling your application’s configuration to specific absolute locations." (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html)
I have a spring web application which takes in an external jar which contains some annotated controllers in packakge com.x.y.controller.
I have included com.x.y.controller package in my component scan path in spring-servlet.xml
<context:component-scan base-package="com.x.y.controller" />.
But When I deploy the application to my local tomcat server, those controller bean in my external jar does not get created.
However, when I extract the jar into my class path when I build the application(meaning having my package fully expanded into my web application class path) everything seems working fine. It seems weird to me because we also have some service classes with #component annotation in external jar. And these class seems working fine.
Does anyone know if it is expected behavior of spring? Or am I missing some configuration for spring to find those controllers?
Currently during development, if I change a class, changes are reflected to tomcat without rebuilding even if the class is in an external jar. If I need to extract the jar for those controllers to work, tomcat does not seem to take in changes in those controllers even if I restart the server. A rebuild is required to extract the jar again for any change to take effect. This would be very painful for development. I am relative new to spring. Does anybody see a solution for this if I have to go that way?
Make sure external.jar exist on your classpath (either by adding to maven dependency, eclipse project settings, using -cp jvm command line arguments, etc), and just refer to the package name of the classes inside external .jar you want to include.
And add <context:annotation-config/> to your spring-servlet.xml
maven module spring application.
1 module is a spring mvc application, another is a non-web but spring managed application.
In my project root, I have:
/src/main/conf
This folder contains my non-web managed spring xml configuration. I added this folder to my class path in intellij.
IntelliJ doesn't pickup the file correctly, meaning I don't get code completion or anything (allot of the names etc. are in bold red i.e. intellij is telling me something is wrong). Can this be fixed somehow?
I have kept my spring mvc config file inside its module (not in the conf folder) because the code completion doesn't work and it's a pain to work with without the IDE helping. But it makes managing things during deployment harder.
In both of my spring config files (for the web app and non-web app), I have my dataSource settings hard-coded in the file, I want to extract this somehow into a properties file, how can I do this?
1 - You can have different spring configuration files all in the same folder, just you need to use different names form them. So, I would use src/main/resources instead to create a new folder in the maven project structure. You will avoid problems.
2- Datasource in both files? why? If you have already two spring configuration files, I would create a third one (application-context-dao.xml) and share the dataSource. How to move properties to a configuration file? See.
I have a J2EE application which has two web.xml files. One is called web.live.xml another is web.dev.xml. I am building this application with maven using profiles. So maven knows which file to choose when packaging.
I was wondering is it possible to make Eclipse use web.dev.xml when packaging my project and deploying it to Tomcat. This would be very useful because web.dev.xml sets some options which decrease start up time of the application.
You can designate the dev xml to be default (and name it web.xml). You can also have maven move (from a different folder) rather than rename.
You can use the Maven resources plugin (http://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html) and configure it with a property in the profile and use that property in the configuration of the filename.