What is the difference between ${spring.version} and literal version number - java

I saw many tutorial some people use maven dependency such way
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
and some people use maven dependency such way
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
What is the main difference between <version>${spring.version}</version> and <version>4.3.3.RELEASE</version> in maven?

The notation of ${spring.version} is a POM variable. This means that somewhere in POM (or in one of parent POMs), you'll see a definition similar to this:
<spring.version>4.3.3.RELEASE</spring.version>
They both achieve the same end result, but using variables is a bit easier to maintain, especially if you use several artifacts sharing the same version. This way, when you choose to upgrade them, you only need to change the version in one place instead of once per artifact.

Related

How can I update the default version of Spring that Intellij provides?

When I create a Spring project in IntelliJ IDEA, it suggests I use Spring 4.1.6. I want to use 4.2.1 (which I can do after creating the project).
Where can I make the change?
Thanks,
Andy
I don't know if you can change that yourself without an upgrade but you can allow it to create it with that version then manually change it your pom.xml file.
For example,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
You can also provide a property that an be used on all your Spring dependencies and then you only have to change it one place.
For example,
<properties>
<org.springframework.version>4.2.0.RELEASE</org.springframework.version>
...
</properties>
Then use it like...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>

Dropwizard no longer supports Java 6

I want to use version 0.6.2 of drop wizard, but it seems to not exist on a maven repository anymore.
The original Maven include was:
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
but according to the website (http://mvnrepository.com/artifact/com.yammer.dropwizard/dropwizard-core/0.6.2), the group and artifact names have changed. On the new page (http://mvnrepository.com/artifact/io.dropwizard/dropwizard-core), the version 0.6.2 does not exist. When I try to do a include like so:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
it doesn’t work. Is there any fix for this? I need to use Dropwizard that supports Java 6.
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
This still works, don't switch over to io.dropwizard unless you want to switch to 0.7.x. 0.6.2 is not available with groupId io.dropwizard. The message is just telling you that future releases will be in the new groupId.

Do I need to download the dependencies that Spring need in Maven?

I am starting out with Spring and I am reading Pro Spring 2.5. On page 17 they talk about Spring dependencies and I wonder if I need to add this myself in the POM, or does the dependency I have added below do this? Such as CGLib, dom4j etc?
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
You shouldn't need to. Maven will read the pom for spring-context and get any necessary dependencies that it has too, so you won't need to specifically put them in your own pom.
Check out this link it's really handy.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
This will just instruct maven that the current POM in which this is declared is dependent on this artfact, so when you compile the app it would make it available for you in classpath

Trying to use Spring LDAP for coding

I am trying to use Spring LDAP for coding
<ldap-server ldif="classpath:my-ldap-clone.ldif" />
but I get this error
NoClassDefFoundError: org/apache/directory/server/core/DirectoryService
What am I doing wrong?
Using maven :
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-all</artifactId>
<version>1.5.7</version>
</dependency>
If you are using Maven, these actually come from an optional dependency of spring-security-ldap.
Using apacheds-all is a bad idea because it embeds a lot of rather common dependencies, like slf4j and dom4j. You would easily get into classloader issues with it.
Instead, you should look inside the pom of the spring-security-ldap version your are using, for the apacheds optional dependencies, and copy them over to your pom without the <scope> and <optional> elements (unfortunately there is no better way to handle optional dependencies with Maven).
For instance, with spring-security-ldap 4.2.2, it would give:
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-core-entry</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-ldap</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-protocol-shared</artifactId>
<version>1.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>1.5.5</version>
</dependency>
(it looks like it hasn't changed since at least 3.2)
Download ApcheDS from below link
http://directory.apache.org/ or get complete jar from here
I have used to work with Spring Security 3.0.5 with LDAP (Spring LDAP 1.3). That time i didn't met requirement of ApacheDS. Check your version of Spring Secuirty which may have dependency with ApacheDS.

Spring maven libraries

I would like to know why some of the libraries are not released during a normal release cycle. For example, from http://repo2.maven.org/maven2/org/springframework/
while spring-core have 3.0.3-RELEASE, spring-remoting and spring-jmx were released only in 2.0.8. Can someone tell me what this would mean? I agree that if there are no changes in the component say spring-jmx then they don't have to release it, but since 90% of the world uses Maven for dependency management can they not just re-release the same libs (of spring-remoting and spring-jmx?)
I ask this because I declare my deps like,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-remoting</artifactId>
<version>${spring.version}</version>
</dependency>
and I would prefer supplying one spring.version instead of keeping version numbers upto date for all components?
The four libraries of interest to me are spring-dao, spring-support, spring-jmx, spring-remoting
spring-remoting and spring-jmx became a part of spring-context, so newer versions are released with spring-context.

Categories