我正在实施一个简单的春季启动应用程序:
Content
上课:
Entity
@Table(name = "content")
public class Content implements Serializable {
public Content() {
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@NotNull
private String title;
//getter/setter and toString()
}
ContentRepository
界面:
@Repository
public interface ContentRepository extends CrudRepository<Content, Long>{
}
RepositoryConfiguration
:
@Configuration
@EnableJpaRepositories({"com.tarameshgroup.derakht.repository"})
@EntityScan("com.tarameshgroup.derakht.domain")
@ComponentScan("com.tarameshgroup.derakht")
public class RepositoryConfiguration {
}
Application
课程进行测试:
@SpringBootApplication
@EnableAutoConfiguration
@Import({RepositoryConfiguration.class})
public class Application {
private static final Logger logger = org.slf4j.LoggerFactory.getLogger(Application.class);
@Autowired
static ContentRepository contentRepository; // Why is null?
public static void main(String[] args) {
logger.info("Running application...");
SpringApplication.run(Application.class);
System.out.println("contentRepository: " + contentRepository); //why contentRepository is null?
}