Essential Spring Tips 01

When the spring property is introduced, the class must have setter and getter methods.

In the spring config file:

Include DAO in Java business class:

	private StudentDao studentDao;
	 // инъекция через атрибуты
	public StudentDao getStudentDao() {
		return studentDao;
	}

	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

When the Spring constructor is introduced, attributes must be specified. The class does not have setter and getter methods, but the constructor must set one method.

<!-Определите экземпляр Bean of Student Hervice и Inject StudentDa->
	<bean id="studentService" class="com.michael.spring.business.student.StudentServiceImpl">		
		<constructor-arg ref="studentDao"></constructor-arg>
	</bean>

Include DAO in Java business class:

private StudentDao studentDao;

	// инъекция через атрибуты

	public StudentDao getStudentDao() {
		return studentDao;
	}

	public void setStudentDao(StudentDao studentDao) {
		this.studentDao = studentDao;
	}

When an attribute is entered, it can be assigned to it, and the return value is determined by the value set for the attribute.

Definition in Java class:

private long youknow;

	public long getYouknow() {
		return youknow;
	}

	public void setYouknow(long youknow) {
		this.youknow = youknow;
	}

<property name="youknow">
	<value>245</value>
</property>

Or write it directly:

<property name="youknow" value="245"></property>

Leave a Comment