I am following a tutorial of Spring. In the example it has created a method with @PostConstructor annotation. But I am trying to put but Spring throws me like a Syntax Error.
Then Spring provide me 3 options:
- Createa Annotation
- Rename in file
- Fix Project setup
Some one know what have I to do?
package cr.test.jba.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cr.test.jba.entity.Role;
import cr.test.jba.repository.BlogRepository;
import cr.test.jba.repository.ItemRepository;
import cr.test.jba.repository.RoleRepository;
import cr.test.jba.repository.UserRepository;
@Service
public class InitDbService {
@Autowired
private RoleRepository roleRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private BlogRepository blogRepository;
@Autowired
private ItemRepository itemRepository;
@PostConstruct
public void init(){
Role roleUser = new Role();
roleUser.setName("ROLE_USER");
}
And applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xmlns:jdbc="http://ift.tt/18IIlo0"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:jpa="http://ift.tt/1iMF6wA"
xsi:schemaLocation="http://ift.tt/18IIlo0 http://ift.tt/11PpghP
http://ift.tt/GArMu6 http://ift.tt/1cQAoMK
http://ift.tt/1iMF6wA http://ift.tt/1j6yiKs
http://ift.tt/OGfeU2 http://ift.tt/UJ63uf
http://ift.tt/GArMu7 http://ift.tt/1tY3uA9">
<context:component-scan base-package="cr.test.jba">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<jdbc:embedded-database type="HSQL" id="datasource" />
<bean class ="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="emf">
<property name="packagesToScan" value="cr.test.jba.entity"></property>
<property name="dataSource" ref="datasource"></property>
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider" />
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="TransactionManager" >
<property name="dataSource" ref="datasource"></property>
</bean>
<jpa:repositories base-package="cr.test.jba.repository" entity-manager-factory-ref="emf" transaction-manager-ref="TransactionManager" />
</beans>
Aucun commentaire:
Enregistrer un commentaire