I know that I'm doing something wrong here, but I can't figure it out and I need your help, please. I'll be brief and get straight to the point:
Repository
enter code here
@Repository
public interface TemplateRepository extends CrudRepository<Template, Integer>{
@Query("select t.temp_code From Template t where t.temp_area = ?1")
public String getTemplateCode(String temp_area);
}
Service @Service("templateservice")
public class TemplateService {
@Autowired
TemplateRepository templateRepository;
@Transactional
public String getLeftMenuArea() {
return templateRepository.getTemplateCode("left_menu");
}
}
Controller
@Controller
public class TemplateController {
@Autowired
static TemplateService templateservice;
public static String getLeftMenu() {
return templateservice.getLeftMenuArea();
}
}
JSP
....
<%
TemplateController tc = new TemplateController();
String test = tc.getLeftMenu();
pageContext.setAttribute("test", test);
%>
<div class="tinymce-single responsive-mg-b-30">
<div class="alert-title">
<h2>Notice</h2>
</div>
<div id="summernote1"> <c:out value="${test}" escapeXml="false" />
</div>
</div>
....
When i run the Application I get the following error message:
SEVERE: Servlet.service() for servlet [spring] in context with path [/eFatura-CE-Systems] threw exception [Beim Verarbeiten von [/WEB-INF/views/index.jsp] ist in Zeile [1078] eine Ausnahme erzeugt worden
1075:
1076: <%
1077: TemplateController tc = new TemplateController();
1078: String test = tc.getLeftMenu();
1079:
1080: pageContext.setAttribute("test", test);
1081: %>
Stacktrace:] with root cause
java.lang.NullPointerException: Cannot invoke "de.efatura.service.TemplateService.getLeftMenuArea()" because "de.efatura.controller.TemplateController.templateservice" is null
at de.efatura.controller.TemplateController.getLeftMenu(TemplateController.java:16)
Does anyone have a better idea than me to fetch data from a MySQL database using Spring Data JPA Method Query and output it in a JSP file?