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.
Related
I recently started the process of migrating some of my applications from Spring Boot 1 to Spring Boot 2 when I noticed something strange.
I usually share my deployment files (i.e. the target folder in a spring boot application generated after calling mvn package ) with other members of my development team through the windows "Share..." feature. This worked well in Spring Boot 1 since the generated files would inherit the file permissions from the parent folder.
However, after migrating to Spring Boot 2, I was surprised to find that the jar files in target/<app_name>-<ver>/WEB_INF/lib do not inherit the file sharing preferences from the parent folder. So other members of my development team only see an empty folder instead of the applications jar dependencies.
Strangely, this does not seem to affect any of the other files in the target folder (static files, class files etc.).
Is this a feature or a bug? Is there a way to make sure that the files in this folder are being shared properly?
I have created a batch file that I can run after calling mvn package but this is an extra step that I would like to avoid.
I am using a spring boot project where I have two module Search and Web. I build war from web module and search module in injected as jar. I have a property file index.properties in search module, So every time I make a jar it goes into search jar, But I want to remove this jar from Search module and want to externalise it to config folder of tomcat. I am using sprinboot project, I don't know how to do this.
System.setProperty("spring.config.name", "search_index");
Does doing this will work ?
If I understand your question correctly
1) You would like to externalized .properties file
2) And you don't want to include .properties in jar file
To answer the first issue there are multiple ways to externalized props file
Try - spring.config.location
Either set this value from your main method or - Inside Tomcat put following value in setenv.sh
Dspring.config.location=/filelocation/application.properties
Reference - https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
To solve the second problem try using exclusion tag in maven config.
like -
<excludes>
<exclude>*.properties</exclude>
</excludes>
My answer is based on the brief understanding provided by you, Please post all the specifics which will helpful to provide correct solution for the issue.
I have a spring web project in eclipse which has folder structure as
src/main/java
src/main/resources
src/test/java
src/test/resources
For some time my eclipse project used to work fine. But recently, when i start the application my eclipse project loads spring annotated beans from
src/test/java
folder.Because of this i am getting
org.springframework.beans.factory.NoUniqueBeanDefinitionException
from spring as there are two implementations of the same spring bean.
When i remove this folder from build path my application works well. Can someone please help with the reason for such behavioral change in my project?
we have two types of ioc containers in spring BeanFactory,ApplicationContext.when a request comes bean factory creates the instance which we declare a bean in xml. but application context creates all bean instances at the time of loading....
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 Spring configured to look up a conf/database.properties file to load some configuration.
This works well outside Tomcat, and in Junit tests, but in Tomcat, it never load. Below the images of this problem.
Configurations:
And:
The properties file in project folder:
The parameters to run Tomcat inside Eclipse:
The temp0 Tomcat Folder, where is all the files being generated Ok:
The Tomcat error log:
https://gist.github.com/4060538
I solved the problem. I think I was using spring in the wrong way.
I changed the follow:
In the library I'm importing/referencing, I removed the line where was importing database.properties file.
I created a spring.xml in my main web app, where in this file I imported the database.properties file and the other app-context.xml files I need to reference.
I think Spring spring don't load properties file outside of the jar. You need to load properties file locally in you main application, and so, references another spring-context.xml files needed.