Nowadays, ubiquitous environments become part of our daily lives. At home, work, cars, hotels, supermarkets and others public spaces we find technologies (electronics and computational elements) that try to make our life simpler and easier in a transparent way. In recent years, the potential of these environments is more and more exploited with the advent and widespread usage of smartphones. This kind of devices enables the execution of applications that are able to adapt seamlessly to the current environment state. These applications, called context-aware applications, benefit from the context information and services that are present in ubiquitous environments to improve and change automatically their behavior. However, such adaptations require the integration of information regarding heterogeneity in terms of devices, execution platforms, and communication protocols as well the mobility of applications so that the different responsibilities of the adaptation can be distributed. In order to face these issues, and considering the limitations of existing solutions, we provide two major contributions in this dissertation: i) SPACES, a middleware approach to integrate context information and ii) Ubiquitous Feedback Control Loops (Ubiquitous FCLs), as an approach to adapt context-aware applications. In particular, in SPACES we define a metamodel inspired on REST (REpresentational State Transfer) for fostering the exchange of context information as resources, which represents the keystone of our approach. Then, we define SPACES Connectors modularizing the different concepts and concerns identified by the metamodel. The connectors are designed by using Component Based Software Engineering (CBSE) principles and then they are incorporated into the Service Component Architecture (SCA) model to be used in different kinds of applications, not only context-aware applications. With the SPACES definition we are able to state the second major contribution- i.e., Ubiquitous FCLs. Inspired on concepts from Autonomic Computing, this kind of FCLs provides the flexibility required to integrate new participants in the adaptation process (e.g., context-aware applications, services and legacy systems) by supporting mobility and the incorporation of new communication mechanisms when required. In the core of the Ubiquitous FCLs-i.e., the decision making- we employ constraint programming techniques to optimize the selected configuration regarding aspects for providing a better user experience, such as the cost associated with the adaptation, the resources consumed or the QoS offered by the new configuration. Finally, we validate our proposal with three case studies: i) a Caching or Off-Loading situation, where the application behavior is modified at runtime, ii) TRACK.ME, a platform for supporting tracking-based scientific experimentations and iii) DIGIHOME, a smarthome platform. These scenarios demonstrate the suitability of our approach when different kinds of devices, protocols and implementation technologies are involved in the adaptation process.