//User.java
@Entity
@Table(name = "User")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
}
//UserRepository.java
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}
//blueprint.xml
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myPersistenceUnit"/>
</bean>
<service ref="entityManagerFactory" interface="javax.persistence.EntityManagerFactory"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<service ref="transactionManager" interface="org.springframework.transaction.PlatformTransactionManager"/>
</blueprint>
//UserService.java
@Component
public class UserService {
@Reference
private UserRepository userRepository;
public void addUser(User user) {
userRepository.save(user);
}
public List<User> getAllUsers() {
return userRepository.findAll();
}
}