Description
Fred Muhlenberg opened SPR-4931 and commented
Reference: http://forum.springframework.org/showthread.php?t=47051
I'm running into an issue with an overloaded set method.
I get different method resolutions depending on the environment in which I run.
I am using the MimeMessageHelper class and am setting the replyTo property and have sample code demonstrating my issue when configuring.
If I run in eclipse, the property requires the String version of the setter.
If I debug in eclipse, the property requires the InternetAddress version of the setter.
If I run from the command line, the property requires the InternetAddress version of the setter.
If I run on our (ancient) 1.4 Oracle App server I need the String version of the setter.
Same source files, same config files, different results.
I assert that if I pass in a bean reference, Spring ought to resolve to an overloaded method to the type of the reference.
My sample test:
Directory Hierarchy
./.classpath
./.project
./build.xml
./lib/activation.jar
./lib/commons-logging-1.0.4.jar
./lib/j2ee.jar
./lib/junit-3.8.1.jar
./lib/junit-4.4.jar
./lib/log4j-1.2.14.jar
./lib/mail.jar
./lib/spring-mock.jar
./lib/spring.jar
./test/java/context-one.xml
./test/java/context-two.xml
./test/java/log4j.properties
./test/java/mderf/MockMimeMessageHelper.java
./test/java/mderf/OneTest.java
./test/java/mderf/TwoTest.java
build.xml
<project name="mailproto" default="all" basedir="." >
<property name="lib.dir" location="lib" />
<property name="build.dir" location="build" />
<property name="build.classes.dir" location="${build.dir}" />
<property name="build.report.dir" location="${build.dir}/report" />
<property name="test.dir" location="test" />
<property name="test.java.dir" location="${test.dir}/java" />
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<!-- <exclude name="**/junit-4.4.jar"/> -->
<exclude name="**/junit-3.8.1.jar"/>
</fileset>
</path>
<path id="test.classpath">
<path refid="compile.classpath" />
<path location="${build.classes.dir}" />
</path>
<target name="init">
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${build.report.dir}"/>
</target>
<target name="all" depends="run">
</target>
<target name="compile" depends="init">
<javac
destdir="${build.classes.dir}"
srcdir="${test.java.dir}"
>
<classpath refid="compile.classpath" />
</javac>
<copy todir="${build.classes.dir}">
<fileset dir="${test.java.dir}">
<include name="*.xml"/>
</fileset>
</copy>
</target>
<target name="run" depends="compile">
<junit
printsummary="true"
fork="yes"
haltonerror="false"
showoutput="true"
>
<classpath refid="test.classpath"/>
<formatter type="xml"/>
<batchtest todir="${build.report.dir}">
<fileset dir="${build.dir}">
<include name="**/*Test.class"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${build.report.dir}">
<fileset dir="${build.report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${build.report.dir}"/>
</junitreport>
<echo>
The JUnit report can be found in ${build.report.dir}/index.html
</echo>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
</project>
context-one.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--!-- **************************************** -->
<!-- Beans associated with email notification -->
<!-- **************************************** -->
<!-- Address of email server -->
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host"><value>localhost</value></property>
</bean>
<bean id="mimeMessage"
factory-bean="javaMailSender"
factory-method="createMimeMessage"/>
<bean id="toMimeMessageHelper" class="mderf.MockMimeMessageHelper">
<constructor-arg type="javax.mail.internet.MimeMessage">
<ref bean="mimeMessage"/>
</constructor-arg>
<property name="replyTo" ref="replyTo"/>
<!-- <property name="replyTo" value="no-reply@localhost"/> -->
<property name="subject" value="Attention: Change Request"/>
</bean>
<!-- Reply address for automated messages -->
<bean id="replyTo" class="javax.mail.internet.InternetAddress">
<property name="address" value="no-reply@localhost"/>
<property name="personal" value="Do Not Reply (Automated Message)"/>
</bean>
</beans>
context-two.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--!-- **************************************** -->
<!-- Beans associated with email notification -->
<!-- **************************************** -->
<!-- Address of email server -->
<bean id="javaMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host"><value>localhost</value></property>
</bean>
<bean id="mimeMessage"
factory-bean="javaMailSender"
factory-method="createMimeMessage"/>
<bean id="toMimeMessageHelper" class="mderf.MockMimeMessageHelper">
<constructor-arg type="javax.mail.internet.MimeMessage">
<ref bean="mimeMessage"/>
</constructor-arg>
<!-- <property name="replyTo" ref="replyTo"/> -->
<property name="replyTo" value="no-reply@localhost"/>
<property name="subject" value="Attention: Change Request"/>
</bean>
<!-- Reply address for automated messages -->
<bean id="replyTo" class="javax.mail.internet.InternetAddress">
<property name="address" value="no-reply@localhost"/>
<property name="personal" value="Do Not Reply (Automated Message)"/>
</bean>
</beans>
log4j.properties
1. direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
1. direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
1. set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=warn, stdout
mderf/MockMimeMessageHelper.java
/*
- MockMimeMessageHelper.java
- Created: Dec 11, 2007
- Version: 1.0
*/
package mderf;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.javamail.MimeMessageHelper;
/**
-
This class
-
@author
Fred Muhlenberg, High Performance Technologies, Inc.
*/
public class MockMimeMessageHelper extends MimeMessageHelper
{
/**@param
arg0
*/
public MockMimeMessageHelper( MimeMessage arg0 )
{
super( arg0 );
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setFrom(javax.mail.internet.InternetAddress)
*/
@Override
public void setFrom( InternetAddress arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setFrom(java.lang.String)
*/
@Override
public void setFrom( String arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setReplyTo(javax.mail.internet.InternetAddress)
*/
@Override
public void setReplyTo( InternetAddress arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setReplyTo(java.lang.String)
*/
@Override
public void setReplyTo( String arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setSubject(java.lang.String)
*/
@Override
public void setSubject( String arg0 ) throws MessagingException
{
}
/**
@param
arg0@param
arg1@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setText(java.lang.String, boolean)
*/
@Override
public void setText( String arg0, boolean arg1 ) throws MessagingException
{
setText( arg0 );
}
/**
@param
arg0@param
arg1@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setText(java.lang.String, java.lang.String)
*/
@Override
public void setText( String arg0, String arg1 ) throws MessagingException
{
setText( arg0 );
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setText(java.lang.String)
*/
@Override
public void setText( String arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setTo(javax.mail.internet.InternetAddress)
*/
@Override
public void setTo( InternetAddress arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setTo(javax.mail.internet.InternetAddress[])
*/
@Override
public void setTo( InternetAddress[] arg0 ) throws MessagingException
{
for( InternetAddress ia : arg0 )
{
setTo( ia );
}
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setTo(java.lang.String)
*/
@Override
public void setTo( String arg0 ) throws MessagingException
{
}
/**
@param
arg0@throws
MessagingException@see
org.springframework.mail.javamail.MimeMessageHelper#setTo(java.lang.String[])
*/
@Override
public void setTo( String[] arg0 ) throws MessagingException
{
for( String str : arg0 )
{
setTo( str );
}
}
}
mderf/OneTest.java
package mderf;
import org.junit.Test;
import org.springframework.test.AbstractSingleSpringContextTests;
public class OneTest extends AbstractSingleSpringContextTests
{
protected String[] getConfigLocations()
{
return new String[]{ "context-one.xml" };
}
@Test
public void testDummy()
{
System.out.println( "Dummy test" );
}
}
mderf/TwoTest.java
package mderf;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TwoTest
{
protected String[] getConfigLocations()
{
return new String[]{ "context-two.xml" };
}
@Test
public void testDummy()
{
new ClassPathXmlApplicationContext( getConfigLocations() );
System.out.println( "Dummy output" );
}
}
Affects: 2.0.2, 2.5 final, 2.5.4
Attachments:
- mailproto.jar (3.42 MB)
Issue Links:
- Avoid ambiguous property warning for setter methods with multiple parameters [SPR-13349] #17933 Avoid ambiguous property warning for setter methods with multiple parameters
- GenericTypeAwarePropertyDescriptor warns when creating java.security.SecureRandom bean [SPR-6399] #11065 GenericTypeAwarePropertyDescriptor warns when creating java.security.SecureRandom bean
Referenced from: commits 4a25e2d