I'm migrating a pretty legacy application to Spring Boot. It is configured with xml and I've got the following snippet there:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="localOverride" value="true"/>
<property name="locations">
<list>
<value>classpath:conf/${ENV}/some.properties</value>
</list>
</property>
</bean>
I'm starting the app with the following command line:
mvn spring-boot:run -Dserver.port=22222 -DENV=int
But it fails on startup with the following message:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'ENV' in value "classpath:conf/${ENV}/some.properties"
It worked before and now I've got spring-boot-starter-web.
Any suggestions? Thank you in advance!
UPDATE: It doesn't work in #PropertySource, not in xml, sorry for misunderstanding
When running the application using maven spring boot plugin(like you are doing) you need to specify like this
mvn spring-boot:run -Drun.arguments="--server.port=22222, --ENV=int"
If you want to run your application using java -jar command. This is the way
java -jar -Dserver.port=22222 -DENV=int XYZ.jar
You should use #systemEnvironment['propertyName'] or
#{systemProperties['propertyName']}
<value>classpath:conf/#{systemEnvironment['ENV']/some.properties</value>
Because
${propertyName}
You can only access properties defined in .properties file
Related
Using PropertyPlaceholderConfigurer to externalize spring-configuration
properties.
Added following code to spring-servlet.xml
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:environment.properties</value>
</property>
</bean>
Filter to be externalized from spring-security.xml
<security:custom-filter position="AUTH_FILTER" ref="${filter}" />
filter value is present in environment.properties
environment.properties file is present inside Jboss modules and is readable from code using resource bundle.
But, with these changes somehow properties file is not getting loaded and following error is thrown while publishing code.
Caused by: java.lang.IllegalArgumentException: Could not resolve
placeholder 'filter' in string value "${filter}"
PS:
Also tried hardcoding path as <value>file:${jboss.home.dir}/modules/system/layers/base/configuration/main/environment.properties</value> but, dosen't seems to be working.
I think your problem is that your spring-servlet.xml is not linked to your spring-security.xml. So spring-security.xml has no knowledged of the PropertyPlaceholderConfigurer.
IMO, you should configure PropertyPlaceholderConfigurer in a properties-context.xml (for instance) so you can import this new file into your spring-servlet.xml and spring-security.xml as following:
<import resource="classpath:properties-context.xml" />
I am developing a spring-shell database migration tool.
At the moment i try to use liquibase with the groovy-dsl extension.
My build.gradle includes the extension jar, also i declared liquibase in the spring-shell-plugin.xml
spring-shell-plugin.xml
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase" depends-on="postgresService">
<property name="dataSource" ref="psqlDataSource"/>
<property name="changeLog" value="com.example.db.DbChangelog_master"/>
<property name="defaultSchema" value="${postgres.schema}"/>
</bean>
But everytime i start the application liquibase throws the following error
Caused by: liquibase.exception.UnknownChangelogFormatException: Cannot find parser that supports com.example.db.DbChangelog_master
at liquibase.parser.ChangeLogParserFactory.getParser(ChangeLogParserFactory.java:70)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:226)
at liquibase.Liquibase.update(Liquibase.java:202)
at liquibase.Liquibase.update(Liquibase.java:192)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:434)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 13 more
The documentation is a bit rare, also the jar is included in the classpath.
Does the groovy scripts need to be in src/main/resources? Currently they are in a seperate package in src/main/groovy
I think that your property
<property name="changeLog" value="com.example.db.DbChangelog_master"/>
is incorrect. This should be the path to your changelog file. If that file is a groovy file, it might be
<property name="changeLog" value="DbChangelog_master.groovy"/>
if that file is available on the classpath.
I am trying to generate apk on command line using ant. I am able to use ant clean but for ant debug and ant release command I am getting following error.
BUILD FAILED
C:\Android\sdk\tools\ant\build.xml:649: The following error occurred while executing this line:
C:\Android\sdk\tools\ant\build.xml:694: Execute failed: java.io.IOException: Cannot run program "C:\Workspace\SampleApp\${aapt}": CreateProcess error=2, Th
e system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:58)...
On line build.xml:694 proguardFile="${out.absolute.dir}/proguard.txt"> line is present. I am using Eclipse Juno and build target is 22 (Lollipop).
Any help is appreciated.
I had the same error after updating the android SDK to the latest build tools.
The tools\ant\build.xml script does not contain any references for the tools.
This can be solved, by adding the tools to the build.xml and point to the correct path. For me this was build-tools\22.0.1
Please compare and update the tool section in build.xml
<!-- tools location -->
<property name="android.tools.dir" location="${sdk.dir}/tools" />
<property name="android.platform.tools.dir" location="${sdk.dir}/platform-tools" />
<property name="android.buildtools.dir" location="${sdk.dir}/build-tools/22.0.1" />
<condition property="exe" value=".exe" else=""><os family="windows" /></condition>
<condition property="bat" value=".bat" else=""><os family="windows" /></condition>
<property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
<property name="lint" location="${android.tools.dir}/lint${bat}" />
<property name="zipalign" location="${android.buildtools.dir}/zipalign${exe}" />
<property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
<property name="aapt" location="${android.buildtools.dir}/aapt${exe}" />
<property name="dx" location="${android.buildtools.dir}/dx${bat}" />
<property name="renderscript" location="${android.buildtools.dir}/llvm-rs-cc${exe}"/>
<property name="lint" location="${android.tools.dir}/lint${bat}" />
Thank you Alex for the tip!
This bit Cannot run program "C:\Workspace\SampleApp\${aapt}"suggests that the variable ${aapt} has not been translated by the compiler.
Check that ${aapt} has been defined earlier in your build script. Try printing out value of ${aapt} (e.g. <echo>aapt variable: ${aapt}</echo>) immediately before the line that triggers the error, to check that the build has correctly compiled the variable.
Just update android sdk tool to 24.3.3
make sure the proguard.config point to an existing proguard file in your project.properties
proguard.config=proguard-project.txt
I am facing an issue when defining mongo repository in application-context.xml
Following is the error i get in xml
Error occured processing XML tried to access method org.springframework.context.annotation.AnnotationConfigUtils.processCommonDefinitionAnnotations
(Lorg/springframework/beans/factory/annotation/AnnotatedBeanDefinition;)V from class org.springframework.data.repository.config.RepositoryComponentProvider'. See Error Log for more details servlet-context.xml /master/WebContent/WEB-INF/config line 24 Spring Beans Problem
I am attaching a screenshot of env for reference.
I am using eclipse Kepler version and pom properties File is like this
<java-version>1.7</java-version>
<org.springframework-version>4.0.1.RELEASE</org.springframework-version>
<org.jackson-version>2.3.0</org.jackson-version>
<spring-data-mongodb>1.4.0.RELEASE</spring-data-mongodb>
Spring data commons version is 1.7
spring data mongo db version 1.4.
I see the error in eclipse project when I open context xml.
Interestingly I have another project that works well.Only difference is that it doesn't have spring MVC and jackson binaries otherwise its similar project.
exception stack trace:
!ENTRY org.springframework.ide.eclipse.beans.core 1 0 2014-03-01
00:04:11.839 !MESSAGE Error occured processing
'/master/WebContent/WEB-INF/config/servlet-context.xml' !STACK 0
java.lang.IllegalAccessError: tried to access method
org.springframework.context.annotation.AnnotationConfigUtils.processCommonDefinitionAnnotations(Lorg/springframework/beans/factory/annotation/AnnotatedBeanDefinition;)V
from class
org.springframework.data.repository.config.RepositoryComponentProvider
at
org.springframework.data.repository.config.RepositoryComponentProvider.findCandidateComponents(RepositoryComponentProvider.java:121)
at
org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.getCandidates(RepositoryConfigurationSourceSupport.java:69)
at
org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:54)
at
org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:88)
at
org.springframework.data.repository.config.RepositoryBeanDefinitionParser.parse(RepositoryBeanDefinitionParser.java:67)
at
org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at
org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)
at
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
at
org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1400)
at
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at
org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1330)
at
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:494)
at
org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:402)
at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at
org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:388)
at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at
servlet context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven />
<context:component-scan base-package="com.xxxx.yyyyy" />
<!-- Mongo DB Configuration -->
<mongo:mongo id="mongo" host="monopolyvm3" port="27017" />
<mongo:db-factory dbname="test" mongo-ref="mongo" />
<mongo:db-factory id="mongoDbFactory" dbname="cloud" mongo-ref="mongo" />
<mongo:repositories base-package="com.xxxx.yyyyy" />
<bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
<bean id="defaultMongoTypeMapper"
class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
<constructor-arg name="typeKey"><null/></constructor-arg>
</bean>
<bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
<constructor-arg name="mappingContext" ref="mappingContext" />
<property name="typeMapper" ref="defaultMongoTypeMapper" />
</bean>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
<constructor-arg name="mongoConverter" ref="mappingMongoConverter" />
<property name="writeConcern" value="SAFE" />
</bean>
</beans>
error is seen at the following line..
In my case it was spring data jpa version which was causing problem. I am not using spring data mongodb but spring data jpa instead. I started this projected today with latest versions (spring-framework 4.0.2.RELEASE, spring-data-jpa 1.5.0.RELEASE). I ensured that all transitive dependencies from maven (from spring side as well as from spring data side) are that of latest version but no lock.
Following this thread, tried to downgrade spring version to 4.0.0.RELEASE but no luck. I even explored the org.springframework.context.annotation.AnnotationConfigUtils class from spring-context-4.0.2.RELEASE.jar (and also in spring-context-4.0.0.RELEASE.jar) from within my workspace and confirmed that indeed processCommonDefinitionAnnotations is a public method thus IllegalAccessError can not be an issue resulting from these jars.
Finally I downgraded my spring-data-jpa from 1.5.0.RELEASE to 1.4.4.RELEASE and voila all problems are solved on maven update. I am using STS 3.4 if it helps anyone.
Since this was the first post I found on googling this error, thought of posting it here so that others who are facing same problems can potentially solve it with this tip. I have opened bug report at https://jira.springsource.org/browse/DATAJPA-490
#Oliver, tried the dependency management suggested but no luck. I have also added dependency:list output to the bug report as requested.
Finally I changed the spring jar version to 4.0.0 and then removed all spring jars from the maven repository and tried to (updated maven first)build again..It worked. I am pretty sure that it will work with 4.0.1 spring jars also.( I was having another project with the same configuration and it was working fine with 4.0.1 jars:)) I contribute this issue to maven and eclipse. Some issue that I don't have any clue at all.
Make sure you don't accidentally pull in an older Spring version (something before 3.2.5) into the classpath. The older methods don't have the method listed in the exception public. This is then causing the exception. I recommend to use the following Maven config snippet to enforce all Spring libraries to be in 4.0.2:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I ran into the same issue. After spending several hours fighting with the problem #Avnish's answer pointed me in the right direction. More specifically, the issue he opened at https://jira.springsource.org/browse/DATAJPA-490 really cleared things up.
Spring-Data-JPA 1.5.1.BUILD-SNAPSHOT or 1.6.0.BUILD-SNAPSHOT has a guard that indicates exactly which jar is causing the problem.
In my case, I was using Eclipse Juno (4.2) with Spring IDE 3.4.0 which was causing the problem. I had to upgrade to Spring IDE 3.5.0 to make the issue go away. I had to use the http://dist.springsource.com/snapshot/TOOLS/nightly/e4.2 update site to update Juno to Spring IDE 3.5.0.
It also appears that STS 3.5.0RC1 and beyond get this working as well.
The real solution is to upgrade your eclipse/STS spring plugin to the latest.
This is mentioned in https://jira.springsource.org/browse/DATAJPA-490, but not that clearly.
My spring context file has this:
<context:property-placeholder location="classpath:web.properties" />
and I reference the key/values like:
<property name="username" value="${dataSource.username}"/>
My file layout is like:
>/www/site/app.war
>/www/site/configs/web.properties
And I run my app using:
>java -cp "/www/site/configs/*.*" -jar app.war
But then I get this exception:
java.io.FileNotFoundException: class path resource [web.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:661)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
Even though I added the files to my classpath, it still can't find it why?
Update
So my config files are here:
/www/site/configs/web.properties
/www/site/configs/log4j.properties
I tried this:
>/www/site/java -cp ".:app.war:/www/site/configs/*.*" com.abc.server.MyServer
and:
>/www/site/java -cp ".:app.war:/www/site/configs/web.properties:/www/site/configs/log4j.properties" com.abc.server.MyServer
and even:
/www/site/java -cp ".:app.war" com.abc.server.MyServer
I get the same error:
2013-04-25 01:19:28.210:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
2013-04-25 01:19:28.294:INFO:oejw.WebInfConfiguration:Extract jar:file:/www/site/app.war!/ to /www/site/work/app
2013-04-25 01:19:32.814:INFO:oejsh.ContextHandler:started o.e.j.w.WebAppContext{/,file:/www/site/app/},file:/www/site/app.war
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2013-04-25 01:19:33.585:INFO:/:Initializing Spring FrameworkServlet 'app'
2013-04-25 01:19:35.750:WARN:/:unavailable
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/web-context.xml]: Could not resolve placeholder 'dataSource.url' in string value [${dataSource.url}]
at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
My web.properties has:
dataSource.url=jdbc:mysql://localhost/appdb
dataSource.username=root
dataSource.password=123
Again my web-context.xml file has:
..
<context:property-placeholder location="classpath*:/web.properties" />
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="${dataSource.url}"/>
<property name="username" value="${dataSource.username}"/>
<property name="password" value="${dataSource.password}"/>
..
I also tried the following variations:
<context:property-placeholder location="classpath:web.properties" />
<context:property-placeholder location="classpath*:web.properties" />
<context:property-placeholder location="classpath*:/web.properties" />
I have also faced similar issues. I cannot say why but I have found -cp arguments not to behave when lugged along with -jar.
You can use,
EDIT
As per the dicussion and going through: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
The correct syntax should be:
In windows:
java -cp "app.war;/www/site/configs/" <Main Class file name>
In Linux:
java -cp "app.war:/www/site/configs/" <Main Class file name>
Items accessible via the CLASSPATH aren't necessarily files at all. They might be still in the JAR or WAR file. They should be accessed as resources, via Class.getResource() and friends.
Entries in the CLASSPATH aren't files either. A CLASSPATH is one or more directories or JAR files inside which the resources are to be found, according to the package structure.