The requested resource () is not available in sample spring mvc application - netbeans

I'm new bee to spring. Just started my sample application in sprinv mvc. But, I can't able to view the page since it is showing "The requested resource () is not available." Cannot figure out where is the problem. I'm pasting the code below.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>my</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>my</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
**
my-servlet.xml
**
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean name="/index.html" class="mypackage.web.myController"/>
</beans>
**
MyController.java
**
package mypackage.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class myController implements Controller{
public ModelAndView handleRequest(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
String msg="Hello!!! I'm coming from Controller. You Catched me ";
ModelAndView mv = new ModelAndView("index");
mv.addObject("message",msg);
return mv;
}
}
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="i" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My First Application in Spring</title>
</head>
<body>
<p>Check Below</p>
<p>
<em>${message}</em>
</p>
</body>
</html>

It's almost configured correctly, so well done so far :-) There are a couple of minor problems here that are causing the problems you see. Firstly, the bean is currently defined with a lowercase m:
<bean name="/index.html" class="mypackage.web.myController"/>
Although this is allowed, it is not conventional, so Spring will not be able to find the correct bean without some additional configuration.
Also, it was not clear from the question which URL you are using, but it should be something of the form http://localhost:8080/<project>/myIndex.html
There is a good summary of the convention here.
So we have 2 options… either rename the class to MyController and save as MyController.java or modify the ControllerClassNameHandlerMapping bean to be case sensitive like so:
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="caseSensitive" value="true" />
</bean>
Furthermore, it is not the cause of the problem but if you use the ControllerClassNameHandlerMapping you can omit bean name, so you can just use:
<bean class="mypackage.web.MyController"/>
I guess the most annoying part is that the web application deploys without error. However if you examine the log, there is a marked difference:
Deployment of incorrectly configured webapp:
04-Jul-2011 09:13:58 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#5f0e7d: defining beans []; root of factory hierarchy
04-Jul-2011 09:13:58 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'my': initialization completed in 157 ms
Deployment of correctly configured webapp:
04-Jul-2011 09:15:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#de537: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,viewResolver,mypackage.web.MyController#0]; root of factory hierarchy
04-Jul-2011 09:15:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/my*] onto handler 'mypackage.web.MyController#0'
04-Jul-2011 09:15:49 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'my': initialization completed in 296 ms
Secondly, once the mapping is fixed, you may discover that the JSP is not found. In the sample I created, I added the views under /WEB-INF/jsp so I needed to update the prefix property in my-servlet.xml to <property name="prefix" value="/WEB-INF/jsp/"/>. However depending on the location of your views, you may not need to do this.
Personally I find the annotation based approach for MVC in Spring much easier to configure and follow, so I will recommend that you read REST in Spring 3: #MVC as you might find that easier to implement.

i was having the same problem because i was following step by step a tutorials thats up on the Netbeans official website, there it says and i quote "note that the JSTL (JavaServer Pages Standard Tag Library) library is added to the classpath during project creation by default. Deselect this option (as in the above screenshot), since you do not require JSTL for this tutorial. " once i tried leaving it checked i could be able to run my sample project, i really dont know anything more, hope this helps someone!

Related

How to configure EJB/JPA in JTA transaction mode?

This is a simple guide for configuring JPA and connecting to your database using JTA transaction mode. Also it is including the most common mistakes that developers do and you should avoid them.
Hope this help you.
1- Set up a DataSource in your Application Server:
In order to configure JPA in your WebApp using JTA mode you need 1st setting up a DataSource. You can setup the DataSource from your Application Server (Glassfish / Payara / ...). but it is recommended to setup the Datasource through your Web App. Follow these steps to setup the DataSource for Glassfish or Payara through your Maven WebApp:
create a new folder (NOT Package) inside your project folder with name "setup".
create a new xml file and name it "glassfish-resources.xml" and save it inside "setup" folder.And write the bellow content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="**jdbc/DBDev01**" object-type="user" pool-name="**jdbc/DBDev01-ConnectionPool**">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false" connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="**org.mariadb.jdbc.MariaDbDataSource**"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="**jdbc/DBDev01-ConnectionPool**"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<!-- for MariaDB users, it recomended to add ?useMysqlMetadata=true, this will make MariaDB pretending that it is a MySQL for tools or libraries that not support MariaDB -->
<property name="URL" value="**jdbc:mariadb://XXX.XXX.XXX.XXX:XXXX/DB_NAME?useMysqlMetadata=true**"/>
<property name="User" value="**USERNAME**"/>
<property name="Password" value="**PASSWORD**"/>
</jdbc-connection-pool>
</resources>
Note: All values in between ** ** should be modified as per your settings.
This file will be loaded by your application server (Glassfish/Payara) after deploying your webapp. For Payara users you can also name the file with "payara-resources.xml" but with little modifications. Ref:Payara Deployment Descriptors.
2- Add Resource reference for the datasource in WEB-INF/web.xml:
you need to add a resource reference for the DataSource in your Webapp through adding this in WEB-INF/web.xml file:
<web-app .....>
......
<resource-ref>
<description>**DBDev01**</description>
<res-ref-name>**jdbc/DBDev01**</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<!-- <res-sharing-scope>Shareable</res-sharing-scope> -->
</resource-ref>
</web-app>
Note: The res-ref-name should match exactly the name you choose for the datasource in glassfish resources file.
3- Configure Persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="**MyDB**" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<!-- List all Entity classes -->
<class>**com.MyEntityClassName**</class>
<jta-data-source>**jdbc/DBDev01**</jta-data-source>
<!-- you can list all entity classes you need and set this value to true. or set this value to false to include other entity clases -->
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!-- while eclipselink not support MariaDB , set this property to enforce eclipselink to work with it as MySQL -->
<property name="eclipselink.target-database" value="MySQL"/>
</properties>
</persistence-unit>
</persistence>
Note 1: If you want to use JTA as transaction type, So you must defining jta-data-source. And it is a common mistake for developers adding DB URL,username and password in properties trying to connect to the database without defining the JTA data Source. This will not work and will lead your application server to use the default datasource that already defined which in common is an H2 database.
Note 2: eclipselink (JPA library) not supporting MariaDB. But there is a workarounds for that.
solution 1:: add "?useMysqlMetadata=true" as suffix on your connection URL Like: <property name="URL" value="**jdbc:mariadb://XXX.XXX.XXX.XXX:XXXX/DB_NAME?useMysqlMetadata=true"/> this will make MariaDB pretending that it is a MySQL.
solution 2: Enforce eclipselink to deal with the database as MySQL. this can be done by setting eclipselink.target-database property in persistence.xml as bellow:
<properties>
<!-- while eclipselink not support MariaDB , set this property to enforce eclipselink to work with it as MySQL -->
<property name="eclipselink.target-database" value="MySQL"/>
</properties>
4- Add JDBC client as Dependency in POM.xml:
<dependency>
<!-- This is for MariaDB. You should change it if you are using other kind of DB like MySQL or Oracle DB -->
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.2</version>
</dependency>
5- Enjoy with your Codes:
writing a sessionBean:
#Stateless
public class StudentManager
{
/* Notes:
1.you should use the same name exactly that defined in Persistence.xml file.
2.You can not use #PersistenceUnit with JTA. only use #PersistenceContext with JTA.
*/
#PersistenceContext(unitName="MyDB")
private EntityManager em;
public StudentManager()
{
}
public void persist(Student student) {
em.persist(student);
}
}
write TestController:
#Named
#SessionScoped
public class TestController
{
#Inject
private StudentManager studentManager;
private String message = "";
public void test()
{
Student student = new Student();
Student.setCode(11223344);
Student.setName("John");
studentManager.persist(Student);
/*Note:we used studentManager directly without constructing.
writing studentManager = new StudentManager() is a common mistake and will lead you to get a null EntityManager.*/
this.setMessage("A new Student already saved successful with Code:" + Student.getCode());
}
Common Question: Should use #Inject or #EJB? here is the answer
A simple JSF page for testing:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Test Save a Student over JTA" action="#{testController.test()}" />
<br />
<h:outputLabel for="message" value="#{test.message}" />
</h:form>
</h:body>
</html>

Eclipse & TomEE: no JPA logging

I am working with Eclipse and TomEE 1.7.1.
If I have a problem with Exception logging of (Open)JPA:
Errors are not logged to console nor to logging file.
For example:
entityManager.createQuery("THIS IS NOT SQL");
If I run this in my WebApp it won't show anything into console.
BUT: If I set a Breakpoint and execute it manually (via Inspect Cntrl+Shift+I) the Exception is shown in console.
WTF is going on???
EDIT:
I have made a test-project with only three files, copied it into Tomee-Webapps-Folder started Tomee directly. Same result: nothing to see in console and no logfile was generated.
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="hprex">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mytest"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="test"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<!-- <property name="openjpa.Log" value="DefaultLevel=TRACE, Runtime=TRACE, Tool=INFO, SQL=TRACE"/> -->
<!-- <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true"/> -->
</properties>
</persistence-unit>
</persistence>
test.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:form>
<h:commandButton action="#{loginBean.login}"/>
</h:form>
</h:body>
</html>
LoginBean.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
#ManagedBean
#SessionScoped
public class LoginBean {
#PersistenceContext(unitName="mytest")
private EntityManager em;
public String login() {
Query query = em.createQuery("This is not SQL");
query.getResultList();
return "test";
}
}
I don't believe this path will result in anything being logged by the JPA provider. When OpenJPA can't create that query, it'll throw an exception back to your application.
what's your setup/config? By default exceptions are logged. You can check: catalina.out, catalina*.log and localhost*.log dependning the config you have for defaults locations (if you use log4j, slf4j...that's on your side to ensure it is logged).

Bayeux Server Configuration Issue

We had an issue with our CometD/Gigaspaces application creating a duplicate instances of the Bayeux Server. See my previous question posted here.
After investigating this issue with Gigaspaces, it turns out each bean defined in our Application Context File was getting created twice as
GigaSpaces has special treatment for Application Context Files called PU.XML. We've resolved this issue by renaming the PU.XML File but the
problem we have now is that we're not receiving any data on the client side and receive the following error "NetworkError: 400 Unknown Bayeux Transport - http://localhost:9292/cometd".
Previously, when the application created a duplicate instance of the Bayeux Server, we put a workaround in place to terminate the first
instance of the thread that the Bayeux Server was running on and as a result we were able to publish data on our channels using Web Sockets which we configured in the
Application Context File.
Could you have a look at our current configuration and let me know if there is a alternative solution to configure and export the Bayeux Server correctly using Spring? Is it possible the Bayeux bean is not getting exported correctly or if it is getting exported too late??
I've posted our updated Web.XML and Application Context configurations below. The CometD Version/Jars in our POM.XML are the same as my previous post. If you need further info. please let me know.
Current Web.XMl:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>CometDApplication</display-name>
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometdServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- <listener>
<listener-class>org.openspaces.pu.container.jee.context.ProcessingUnitContextLoaderListener</listener-class>
</listener>-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-gigaspaces.xml</param-value>
</context-param>
</web-app>
Current applicationContext-gigaspaces.XML:
<bean id="Bayeux" class="org.cometd.server.BayeuxServerImpl"
init-method="start" destroy-method="stop">
<property name="options">
<map>
<entry key="logLevel" value="0" />
<entry key="timeout" value="15000" />
</map>
</property>
<property name="transports">
<list>
<!-- The order of the following transports dictates the type of transport
used i.e. Web Sockets then JsonTransport (a.k.a long-polling) -->
<bean id="websocketTransport" class="org.cometd.websocket.server.WebSocketTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonTransport" class="org.cometd.server.transport.JSONTransport">
<constructor-arg ref="Bayeux" />
</bean>
<bean id="jsonpTransport" class="org.cometd.server.transport.JSONPTransport">
<constructor-arg ref="Bayeux" />
</bean>
</list>
</property>
</bean>
<!-- Export the Bayeux Server to the servlet context via springs ServletContextAttributeExporter -->
<bean id="ContextExporter"
class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="org.cometd.bayeux">
<ref local="Bayeux" />
</entry>
</map>
</property>
</bean>
The code you posted is correct and virtually identical to the test present in CometD, see here and here.
You have something else going on, and debug logs on both client and server will help you understanding.

Exception java.lang.NullPointerException accurs while trying to reach the service layer from my controller

I'm working with Spring STS (Also with Eclipse-juno, spring 3.1), and creating a spring template project.
My welcome page of the application is a simple form:
<div id="editPresPage">
<form action="editPresPage.do" method="post">
<label>Enter Page Text</label><input type="text" name="page_text"/><br>
<input type="submit" value="Add New Page"/>
</form>
</div>
When i deliver the form ,My controller comes into place:
#Controller
#RequestMapping(value = "/")
public class HomeController {
private Page_manager_service page_manager_service;
public void setPage_manager_service(Page_manager_service page_manager_service) {
this.page_manager_service = page_manager_service;
}
#RequestMapping(value="/editPresPage",method = RequestMethod.POST)
public ModelAndView EditPresPage() {
page_manager_service.check();
return new ModelAndView("thanks");
}
The controller needs to perform the check method (which is marked) from My Service Layer interface:
public interface Page_manager_service {
public void check();
}
The Service Layer implementation:
public class Page_manager_service_mock_Impl implements Page_manager_service {
public void check() {
System.out.println("check method was done!!!");
}
}
But i'll getting the following error while executing the check method:
java.lang.NullPointerException
at my.topLevel.pack.HomeController.EditPresPage(HomeController.java:64)
Here is my servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="my.topLevel.pack" />
</beans:beans>
Here is my root-context.xml (you can see that i wired the "page_manager_service" bean):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<context:annotation-config/>
<!-- Service Beans -->
<bean id="page_manager_service" class="my.topLevel.pack.Services.Page_manager_service_mock_Impl">
</bean>
</beans>
I did not change anything in the web.xml file.
I can see that the service layer implementation is being injected because there is an "s" on it.
I'm able to transfer parameters from the view to the controller- so the problem isn't there.
It's in the controller<-> service layer communication.
I Don't know why i'm getting this error..
The problem was solved by doing this steps:
First step:Adding #Autowired to the page_manager_service field (It's ok to delete the setter).
Second step: In the root-context.xml file changing:
<context:annotation-config/>
to:
<context:component-scan
base-package="my.topLevel.pack">
</context:component-scan>
Third Step: Removing:
<bean id="page_manager_service" class="my.topLevel.pack.Services.Page_manager_service_mock_Impl">
from root-context.xml.
Fourth Step:Adding #Component to Page_manager_service_mock_Impl
Although you have created the Page_manager_service bean, it has not been injected into the Controller class, causing the NPE when you call
page_manager_service.check();
You could annotate Page_manager_service with #Component and autowire the Controller:
#Autowired
private Page_manager_service page_manager_service;
The setter will then be unnecessary ...
Side Note: Java uses camel-case which would make page_manager_service pageManagerService.

Alfresco Share: renaming label on workflow forms

I need to rename some labels on workflow forms. I think I've found the resource bundle that need to be edited. It's slingshot.properties file.
I changed values of workflow.field.message and workflow.field.comment to my preference and restarted Alfresco but nothing's changed. Did I miss something?
In $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/web-extension, create a new file called custom-slingshot-application-context.xml with the following content:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="mycustom.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.web-extension.messages.mycustom</value>
</list>
</property>
</bean>
</beans>
In $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/web-extension/messages, create a file called mycustom.properties with the following content:
workflow.field.message=Whatever You Want
Restart Tomcat
Notes:
Please use something more descriptive than "mycustom" in both the
bean ID and the properties file name. This is just an example.
Create folders where they don't exist already.