Entity, Repository ๋ฅผ ์ธ์ ๋ชปํ๋ ๋ฌธ์
Consider defining a bean of type '~~~~~' in your configuration repository.
Not a managed type: class com.test.entity.function.Function
์ด๊ฑธ๋ก ๋ช ์๊ฐ์ ๋ ๋ ธ๋ ๋ชจ๋ฅด๊ฒ ๋ค.
ํ์ฌ ์คํ๋ง๋ถํธ ๊ธฐ๋ฐ์ผ๋ก ์ ํค์๋๋ฅผ ๊ฒ์ํ๋ฉด ์คํ๋ง ๋ถํธ application์ด ์ ์ธ๋ ๊ณณ์
@EntityScan
@EnableJpaRepositories๋ฅผ ๋ฌ์๋ผ๊ณ ํ๋ค.
์๋ ๋ธ๋ก๊ทธ๋ ์๋ฃจ์ ์ ํ ์์ด๋ค.
๊ทธ๋ฐ๋ฐ ์๋ฌด๋ฆฌ ์๋ฃจ์ ์ ๋ฐ๋ผํด๋, @EntityScan์ ํด๋, @~Repository๋ฅผ ํด๋ ๊ณ์ํด์ ํน์ ํจํค์ง์ ์ ์ธํ Entity, Repository๋ฅผ ์ฝ์ด์ค์ง ๋ชปํ๋ค.
๊ทผ๋ฐ ํน์ ํจํค์ง ์์ Entity์ Repository๋ ์ ์ค์บํด์ค๋ ๊ฒ ๊ฐ์ ๊ทธ ํจํค์ง ๋ช ์ ๊ฒ์ํด๋ณด์๋๋...
(๊ทธ ํจํค์ง๋ช ์ taxonomy)
JPA๋ฅผ Configuration class์์
@EnableJpaRepositories(
basePackages = ""
...
)
์ ์ธํ ๊ณณ์ "taxonomy"๋ฅผ ๋ด๊ฐ ๋ช ์ํ ๊ฒ์ด ์๋๊ฐ!!!
๊ฑฐ๊ธฐ๋ค ์์ค์ฝ๋ ๋ด๋ถ์์ setPackageToScan์ ํ ๋๋ ํจํค์ง์ taxonomy๋ผ๊ณ ๋ด๊ฐ ๋ช ์๋ฅผ ํด๋ฒ๋ ธ๋๊ฒ....
๊ทธ๋์ ์๋ฌด๋ฆฌ main ํด๋์ค์์ EntityScan, EnableRepository ๋ฅผ ์ค์ ํด์ค๋ ์ ๋๋ ๊ฒ์ด๋ค!!!
@Configuration
@EnableTransactionManagement
@PropertySource({"classpath:db-dev.properties"})
@EnableJpaRepositories(
basePackages = "com.app.repository", //์๋๋ com.app.repository.taxonomy
entityManagerFactoryRef = "entityManagerFactory",
transactionManagerRef = "transactionManager")
public class DataSourceConfig
{
private final Environment env;
public DataSourceConfig(Environment env) {this.env = env;}
@Primary
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource()
{
System.out.println("DATA SOURCE......");
return DataSourceBuilder.create().build();
}
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory()
{
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setDataSource(dataSource());
factory.setPackagesToScan("com.app.model.entity"); //์๋๋ com.app.model.entity.taxonomy
final HashMap<String, Object> properties = new HashMap<>();
properties.put("hibernate.dialect", env.getProperty("spring.jpa.properties.hibernate.dialect"));
properties.put("hibernate.show-sql", env.getProperty("spring.jpa.show-sql"));
properties.put("hibernate.format-sql", env.getProperty("spring.jpa.format-sql"));
factory.setJpaPropertyMap(properties);
// factory.afterPropertiesSet();
System.out.println("ENTITY MANAGER FACTORY......");
return factory;
}
๊ทธ๋๋ ์์ธ์ง ๋ต์ ์๊ฒ๋์ ๋คํ์ด๋ค.
๋๊ธ